2015-12-06 64 views
-1

我想在Google地图上找到坐标。通过标记显示Google地图上的坐标

我的ID,并从JSON坐标

我从JSON哪些是未来像

坐标的坐标= - 12.9487,9.0131]

我想向他们展示谷歌地图通过标记..

谁能告诉我如何表达

我们在谷歌地图 var myLatlng = new google.maps.LatLng(-25.363882,131.044922);

但它们是不同的值不是数组。如何通过标记在谷歌地图上显示我的JSon坐标[-12.9487,9.0131]。

+0

什么顺序坐标数组中的数字?他们是'[纬度,经度]还是'[经度,纬度]'? – geocodezip

回答

0
var coordinates =[-12.9487,9.0131]; 

将是([latitude, longitude]):

var myLatlng = new google.maps.LatLng([coordinates[0],coordinates[1]); 

或([longitude,latitude]):

var myLatlng = new google.maps.LatLng([coordinates[1],coordinates[0]); 

我要去承担第二,因为首先是在中间海洋。

var coordinates = [-12.9487, 9.0131]; 
 

 
function initialize() { 
 
    var myLatlng = new google.maps.LatLng(coordinates[1], coordinates[0]); 
 
    var map = new google.maps.Map(
 
    document.getElementById("map_canvas"), { 
 
     center: myLatlng, 
 
     zoom: 13, 
 
     mapTypeId: google.maps.MapTypeId.ROADMAP 
 
    }); 
 
    var marker = new google.maps.Marker({ 
 
    position: myLatlng, 
 
    map: map 
 
    }) 
 

 
} 
 
google.maps.event.addDomListener(window, "load", initialize);
html, 
 
body, 
 
#map_canvas { 
 
    height: 100%; 
 
    width: 100%; 
 
    margin: 0px; 
 
    padding: 0px 
 
}
<script src="https://maps.googleapis.com/maps/api/js"></script> 
 
<div id="map_canvas"></div>

相关问题