簡體   English   中英

Google Map cordova ios 中的方向問題

[英]Google Map Direction issue in cordova ios

當我點擊方向鏈接時,它會顯示從其他地方的方向,而不是顯示從當前位置到目的地的方向。

I am working on Cordova, in android it's shows the direction from current location to destination, this issue is not there but in iOS 11 version I am getting this issue, in iOS 10 version it is working.

我在 URL 下方使用了 Google Map 方向,它將自動填充我當前的位置,但它顯示的是其他位置而不是當前位置。

var mapLocationUrl = "https://www.google.com/maps/dir/?api=1&destination=" + lat + "," + long;

window.open(encodeURI(mapLocationUrl), '_system', 'location=yes');

function geocodeAddress() {
    var address = $("#address1").text() + $("#address2").text();
    geocoder.geocode({ address: address }, function (results, status) {
        if (status == google.maps.GeocoderStatus.OK) {
            var p = results[0].geometry.location;
            var lat = p.lat();
            var lng = p.lng();
            datastring = 'compId=' + compid + "&lat=" + lat + "&long=" + lng;
        }
    });
}

添加了屏幕截圖,因為它沒有從自動檢測當前位置而不是那個位置獲取方向,它指向其他地方

使用 Javascript 庫

<html>
   <head>
      ...    
         ...
         <style>
         #map {
         height: 100%;
                 top: 0px;
             }
         </style>    
             </head>
             <body>
             ...
             <div id="map"></div>
             ...
         <script>
          function initMap() {
         var directionsService = new google.maps.DirectionsService;

                         var directionsDisplay = new google.maps.DirectionsRenderer;

                         map = new google.maps.Map(document.getElementById('map'), {
                             zoom: 10,
                             center: {
                                 lat: 0.0..,
                                 lng: 0.0...
                             },
                             disableDefaultUI: true,
                             mapTypeControl: false
                         });
         map.setTilt(45);
         directionsDisplay.setMap(map);
         calculateAndDisplayRoute(directionsService, directionsDisplay);
         }
         function calculateAndDisplayRoute(directionsService, directionsDisplay) {
                         directionsService.route({
                             origin: startLocation, //String or lat long
                             destination: endLocation, //String or lat long
                             waypoints: waypoints, //[String or lat long]
                             optimizeWaypoints: true, 
                             travelMode: 'DRIVING'
         }, function (response, status) {
         if (status === 'OK') {
         directionsDisplay.setDirections(response);
         } else {
                                 if (status == "ZERO_RESULTS")
                                     window.alert("Wrong address found");
                                 else if (status == "MAX_WAYPOINTS_EXCEEDED")
                                     window.alert("Maximun address entered ");
                                 else
                                     window.alert("Wrong address");
                             }
         });
                     }
      </script>
      <script async defer src="https://maps.googleapis.com/maps/api/js?key=B****&callback=initMap">
      </body>
      <html>

或者直接啟動谷歌和蘋果地圖進行導航。

function Dir() {
    var saddr = startLocation;
    var daddr = endLocation;
    //Load Apple Maps
    var url = "http://maps.apple.com/?daddr=" + daddr + "&dirflg=d&t=m"
    //Launch google maps
    var url = "https://www.google.com/maps/dir/?api=1&origin=My+Location&destination=" + daddr + "&travelmode=driving&dir_action=navigate"
    window.location.href = url;
}

更多細節
Apple URL 方案參考。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM