我想显示一个基于状态,城市,地区,纬度和经度的地图从数据库中获取并显示在merker通知中。
答案 0 :(得分:0)
纬度 “name =”latitude“> 经度 “name =”经度“> 返回/取消“; ?>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
var addssByGoogle='<?=$fetch['latitude']?>,<?=$fetch['longitude']?>';
var geocoder;
var map;
var infowindow = new google.maps.InfoWindow();
var marker;
function initialize(address,xLocation,yLocation)
{
codeLatLng(address,xLocation,yLocation) ;
}
function codeLatLng(address,xLocation,yLocation)
{
var latlng = new google.maps.LatLng(xLocation,yLocation);
var myOptions = {
center: latlng,
mapTypeId: 'roadmap'
}
geocoder = new google.maps.Geocoder();
map = new google.maps.Map(document.getElementById("map_canvas1"), myOptions);
geocoder.geocode({'latLng': latlng}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
if (results[0]) {
if('1.366667'==xLocation && '103.8'==yLocation)
{
map.setZoom(9);
}
else
{
map.setZoom(12);
}
marker = new google.maps.Marker({
position: latlng,
map: map,
title: address
});
addssByGoogle = results[0].formatted_address;
//infowindow.setContent(results[0].formatted_address);
infowindow.setContent(address);
infowindow.open(map, marker);
} else {
// alert("No results found");
}
} else {
// alert("Geocoder failed due to: " + status);
}
});
}
</script>
<div id="map_canvas1" style="width:100%; height:300px;"></div>
<script type="text/javascript">
initialize("Latitude: <?=$fetch['latitude']?><br/> Longitude: <?=$fetch['longitude']?>","<?=$fetch['latitude']?>","<?=$fetch['longitude']?>");
</script>