2017-06-26 16 views
0

我有一个问题,目前我有一些标记,我从一个xml文件使用经纬度位置获得。谷歌地图 - Javascript的 - 如何启用点击标记监听器,如果正在使用手机来激活gps方向

所以我想知道如何启用标记侦听器选项来激活或显示发送用户使用手机方向(GPS)的选项。就像在Android中,我点击标记它显示激活gps方向的选项,但在网上我不知道如何。

所以对于每个方向如果点击发送当前位置到手机的gps方向app。

Currlently我有这样的代码:

function initMap() { 


    var map = new google.maps.Map(document.getElementById('map'), { 
     center: {lat: -34.397, lng: 150.644}, 
     zoom: 12 
    }); 
    var infoWindow = new google.maps.InfoWindow({map: map}); 



    // Try HTML5 geolocation. 
    if (navigator.geolocation) { 
     navigator.geolocation.getCurrentPosition(function(position) { 
     var pos = { 
      lat: position.coords.latitude, 
      lng: position.coords.longitude 
     }; 

     infoWindow.setPosition(pos); 
     infoWindow.setContent('Location found.'); 
     map.setCenter(pos); 
     }, function() { 
     handleLocationError(true, infoWindow, map.getCenter()); 
     }); 
    } else { 
     // Browser doesn't support Geolocation 
     handleLocationError(false, infoWindow, map.getCenter()); 
    } 


     // Change this depending on the name of your PHP or XML file 
     downloadUrl('https://www.mysite/dataMaps.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({ 
      map: map, 
      position: point, 
      label: icon.label 
      }); 
      marker.addListener('click', function() { 
      infoWindow.setContent(infowincontent); 
      infoWindow.open(map, marker); 
      //map.setCenter(marker.getPosition()); 

      }); 
     }); 
     }); 



    } 

而且

我foun这在谷歌网站:

 function displayRoute(origin, destination, service, display) { 
     service.route({ 
     origin: origin, 
     destination: destination, 
     waypoints: [{location: 'Adelaide, SA'}, {location: 'Broken Hill, NSW'}], 
     travelMode: 'DRIVING', 
     avoidTolls: true 
     }, function(response, status) { 
     if (status === 'OK') { 
      display.setDirections(response); 
     } else { 
      alert('Could not display directions due to: ' + status); 
     } 
     }); 
    } 

但在航路点:不知道如何发送经纬度参数并且如果它能在移动设备上运行以触发GPS定位应用:S

有什么建议吗?

回答