【发布时间】:2010-11-11 18:10:11
【问题描述】:
使用地理编码初始化谷歌地图时遇到一些问题。第一个问题是在 $gmap 字符串中使用了任何逗号,第二个问题是获得“gmap_initialize is not defined”。我知道函数之外的一切都是正确的,有什么想法吗?
<?php $gmap = "Prague, Czech Republic"; ?>
<script type="text/javascript">
function gmap_initialize() {
var geocoder = new google.maps.Geocoder();
geocoder.geocode( { 'address': <?php echo $gmap; ?>}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var options = {
zoom: 16,
position: results[0].geometry.location,
center: results[0].geometry.location,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map_canvas"), options);
var marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location
});
} else {
alert("Geocode was not successful for the following reason: " + status);
}
});
}
</script>
【问题讨论】:
标签: google-maps geocoding