【问题标题】:Displaying google maps pinpoints near a certain specified location在某个指定位置附近显示谷歌地图的精确定位
【发布时间】:2011-01-17 07:30:38
【问题描述】:
【问题讨论】:
标签:
javascript
google-maps
google-maps-api-3
【解决方案1】:
想通了,这就是你的做法:
注意:$default 包含您最初希望显示的城市纬度/经度。 mapEvents() 返回一个包含事件的所有 lat/lng/title 的数组。
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
var map;
function initialize() {
var myLatlng = new google.maps.LatLng(<?= $default ?>);
var myOptions = {
zoom: 9,
center: myLatlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
<?php
$pinpoints = mapEvents();
foreach ($pinpoints as $pinpoint) {
$loc = $pinpoint['UA_LAT'] . "," . $pinpoint['UA_LNG'];
echo("
var myLatlng = new google.maps.LatLng(" . $loc . ");
var marker = new google.maps.Marker({
position: myLatlng,
map: map,
title: '" . $pinpoint['EVENT_NAME'] . "'
});
");
$loc = "";
}
?>
}
</script>