2015-04-23 52 views
-1

我從here 得到谷歌地圖繪製折線的代碼,但我想根據經度和緯度得到地圖的重點,所以我加了這條線 - > map.setCenter(新的google.maps.LatLng(-122.5868225097656,45.56117947133065)); 但折線沒有出現由於緯度和經度的屏幕和我加入(map.setCenter)行沒有任何改變 這裏外面是代碼:專注於谷歌地圖API根據經緯度

<!DOCTYPE html> 
<html> 
    <head> 
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no"> 
    <meta charset="utf-8"> 
    <title>Simple Polylines</title> 
    <style> 
     html, body, #map-canvas { 
     height: 100%; 
     margin: 0px; 
     padding: 0px 
     } 
    </style> 
    <script src="https://maps.googleapis.com/maps/api/js?v=3.exp&signed_in=true"></script> 
    <script> 

function initialize() { 
    var mapOptions = { 
    zoom: 3, 
    center: new google.maps.LatLng(0, -180), 
    mapTypeId: google.maps.MapTypeId.TERRAIN 
    }; 

    var map = new google.maps.Map(document.getElementById('map-canvas'), 
     mapOptions); 
    map.setCenter(new google.maps.LatLng(-122.5868225097656,45.56117947133065)); 
    var flightPlanCoordinates = [ 
    new google.maps.LatLng(-122.5868225097656,45.56117947133065), 
    new google.maps.LatLng(-122.6348876953125,45.493833740092185) 
    ]; 

    var flightPath = new google.maps.Polyline({ 
    path: flightPlanCoordinates, 
    geodesic: true, 
    strokeColor: '#FF0000', 
    strokeOpacity: 1.0, 
    strokeWeight: 2 
    }); 

    flightPath.setMap(map); 
} 

google.maps.event.addDomListener(window, 'load', initialize); 

    </script> 
    </head> 
    <body> 
    <div id="map-canvas"></div> 
    </body> 
</html> 

回答

1
-122.5868225097656,45.56117947133065 
-122.6348876953125,45.493833740092185 

是無效的latlong(s)。這就是爲什麼應用程序不能正常工作的原因。

我試圖互換這些值。並且工作得很好。

map.setCenter(new google.maps.LatLng(45.56117947133065,-122.5868225097656)); 
    var flightPlanCoordinates = [ 
    new google.maps.LatLng(45.56117947133065,-122.5868225097656), 
    new google.maps.LatLng(45.493833740092185,-122.6348876953125) 
    ]; 
+0

它的工作,非常感謝:) –

+0

@ Engy.Mostafa請接受我的答案,如果它幫助你。 :) – Eddie