Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <script>
- // Note: This example requires that you consent to location sharing when
- // prompted by your browser. If you see the error "The Geolocation service
- // failed.", it means you probably did not give permission for the browser to
- // locate you.
- var customLabel = {
- restaurant: {
- label: 'R'
- },
- bar: {
- label: 'B'
- }
- };
- function initMap() {
- var map = new google.maps.Map(document.getElementById('map'), {
- center: new google.maps.LatLng(-23.568130, -46.649166),
- zoom: 13, scrollwheel: !1
- });
- var infoWindow = new google.maps.InfoWindow;
- downloadUrl('resultado.php', function (data) {
- var xml = data.responseXML;
- var markers = xml.documentElement.getElementsByTagName('marker');
- Array.prototype.forEach.call(markers, function (markerElem) {
- var name = markerElem.getAttribute('name');
- var address = markerElem.getAttribute('address');
- var type = markerElem.getAttribute('type');
- var point = new google.maps.LatLng(
- parseFloat(markerElem.getAttribute('lat')),
- parseFloat(markerElem.getAttribute('lng')));
- var infowincontent = document.createElement('div');
- var strong = document.createElement('strong');
- strong.textContent = name;
- infowincontent.appendChild(strong);
- infowincontent.appendChild(document.createElement('br'));
- var text = document.createElement('text');
- text.textContent = address;
- infowincontent.appendChild(text);
- var icon = customLabel[type] || {
- };
- var marker = new google.maps.Marker({
- position: point,
- label: icon.label,
- icon: 'pointer.png',
- map: map
- });
- marker.addListener('click', function () {
- infoWindow.setContent(infowincontent);
- infoWindow.open(map, marker);
- });
- });
- });
- function downloadUrl(url, callback) {
- var request = window.ActiveXObject ?
- new ActiveXObject('Microsoft.XMLHTTP') :
- new XMLHttpRequest;
- request.onreadystatechange = function () {
- if (request.readyState == 4) {
- request.onreadystatechange = doNothing;
- callback(request, request.status);
- }
- };
- request.open('GET', url, true);
- request.send(null);
- }
- function doNothing() {}
- var infoWindow = new google.maps.InfoWindow({map: map});
- if (navigator.geolocation) {
- navigator.geolocation.getCurrentPosition(function (position) {
- var pos = {
- lat: position.coords.latitude,
- lng: position.coords.longitude
- };
- infoWindow.setPosition(pos);
- infoWindow.setContent('Você está aqui');
- map.setCenter(pos);
- }, function () {
- handleLocationError(true, infoWindow, map.getCenter());
- });
- } else {
- handleLocationError(false, infoWindow, map.getCenter());
- }
- }
- function handleLocationError(browserHasGeolocation, infoWindow, pos) {
- infoWindow.setPosition(pos);
- infoWindow.setContent(browserHasGeolocation ?
- 'Error: The Geolocation service failed.' :
- 'Error: Your browser doesn\'t support geolocation.');
- }
- </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement