如何在Google地图中标记位置

时间:2012-11-05 13:50:04

标签: php google-maps google-maps-api-3

我有Geo位置。我正在尝试将此位置标记为Google地图。请建议我最好的方法。我拥有要在Google地图中使用的数组中的所有位置

        Array
        (
            [0] => 51.508742, -0.134583
        )
        Array
        (
            [0] => 38.410558, 17.314453
        )

1 个答案:

答案 0 :(得分:4)

https://developers.google.com/maps/documentation/javascript/overlays#Markers

//var myLatlng = new google.maps.LatLng(-25.363882,131.044922);
var myLatLng = new google.maps.LatLng(yourArrayName[0][0], yourArrayName[0][1]);
var mapOptions = {
    zoom: 4,
    center: myLatlng,
    mapTypeId: google.maps.MapTypeId.ROADMAP
}
var map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);

var marker = new google.maps.Marker({
    position: myLatlng,
    map: map,
    title:"Hello World!"
});

将数组设置为包含具有不同元素的纬度和经度的数组可能更容易,而不是像您看到的那样包含一个字符串。

相关问题