【发布时间】:2014-03-10 10:16:15
【问题描述】:
我想创建一个谷歌地图,其中我要显示的标记来自数据库,信息窗口数据也来自数据库,显然每个标记都不同。我现在使用的代码是:
<script type="text/javascript">
var delay = 100;
var infowindow = new google.maps.InfoWindow();
var latlng = new google.maps.LatLng(21.0000, 78.0000);
var mapOptions = {
zoom: 5,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
var geocoder = new google.maps.Geocoder();
var map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
var bounds = new google.maps.LatLngBounds();
function geocodeAddress(address, next) {
geocoder.geocode({address:address}, function (results,status){
if (status == google.maps.GeocoderStatus.OK) {
var p = results[0].geometry.location;
var lat=p.lat();
var lng=p.lng();
createMarker(address,lat,lng);
}else {
if (status == google.maps.GeocoderStatus.OVER_QUERY_LIMIT) {
nextAddress--;
delay++;
} else {}
}
next();
});
}
function createMarker(add,lat,lng) {
var contentString = add;
var marker = new google.maps.Marker({
position: new google.maps.LatLng(lat,lng),
map: map
});
google.maps.event.addListener(marker, 'click', function() {
infowindow.setContent(contentString);
infowindow.open(map,marker);
});
bounds.extend(marker.position);
}
<?php
global $wpdb;
$results = $wpdb->get_results("select * from $wpdb->postmeta where meta_value = 'Canada'");
$num_rows = $wpdb->num_rows;
?>
var locations = [
<?php foreach ($results as $doc_meta_data) {
echo "'";// . $doc_meta_data->meta_id;
echo get_post_meta($doc_meta_data->post_id, 'address', true).",";
echo get_post_meta($doc_meta_data->post_id, 'state', true).",";
echo get_post_meta($doc_meta_data->post_id, 'country', true);
echo "',";
}?>
];
var nextAddress = 0;
function theNext() {
if (nextAddress < locations.length) {
setTimeout('geocodeAddress("'+locations[nextAddress]+'",theNext)', delay);
nextAddress++;
} else {
map.fitBounds(bounds);
}
}
theNext();
</script>
如何添加使每个标记信息动态,即,它应该来自管理面板。 网址:http://intigateqatar.com/ozone/find-a-doc/
【问题讨论】:
-
问题是……?
-
如何使每个标记信息窗口动态化,即它们应该随每个标记而变化。
标签: google-maps google-maps-markers infowindow