据我所知,你陷入了想要从数据库中获取数据的部分,并根据纬度和经度呈现一个具有位置的地图..如果这是正确的,你可以尝试这个..
基于此链接https://developers.google.com/maps/articles/phpsqlsearch_v3?hl=es#createtable上的示例
这是适合我的代码(我不知道是否有任何冗余)。
//select statement that grabs latitude and longitude for the current user and stores them to variables eg $lat and $lng. Then you just echo them below into the javascript.
?>
var map;
var geocoder;
function InitializeMap() {
var latlng = new google.maps.LatLng(<?php echo $lat; ?>, <?php $lng; ?>);
var myOptions =
{
zoom: 8,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP,
disableDefaultUI: true
};
map = new google.maps.Map(document.getElementById("map"), myOptions);
}
window.onload = InitializeMap;