PHP-Google Map API 3标记未显示
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了PHP-Google Map API 3标记未显示,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1619字,纯文字阅读大概需要3分钟。
内容图文
![PHP-Google Map API 3标记未显示](/upload/InfoBanner/zyjiaocheng/675/d92912702e134a1bad10465bebac2132.jpg)
我正在使用Google Map API 3和Google Geocoder.问题是它没有显示标记和信息窗口,而是通过ajax带来了数据,并调用了函数showAddress(elemId,address),其中elementId是div ID,将在其中渲染地图.这是谷歌地图的代码
<script type="text/javascript">
//<![CDATA[
var geocoder;
var map;
var lat;
var lng;
function showAddress(elemId, address) {
geocoder = new google.maps.Geocoder();
geocoder.geocode( { 'address': address}, function(results, status){
// console.log(results[0].geometry.location.YA);
lat = results[0].geometry.location.Ya;
lng = results[0].geometry.location.Za;
var mapOptions = {
zoom: 15,
center: new google.maps.LatLng(lat, lng),
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById(elemId),
mapOptions)
$('a#full-'+elemId).attr('href','http://maps.google.com/maps?f=q&source=s_q&hl=en&geocode=&q='+lat+','+lng+'')
var marker
marker = "marker_"+elemId;
myLatlng = new google.maps.LatLng(lat,lng);
marker = new google.maps.Marker({
id:elemId,
position: myLatlng,
map: map
});
var infowindow = "infowindow"+elemId;
infowindow = new google.maps.InfoWindow({
content: 'Hello world'
});
infowindow.open(map, marker);
google.maps.event.trigger(map, 'resize');
});
}
</script>
解决方法:
首先.Ya和.Za不是文档化的属性,因此,如果您按如下方式使用它们
lat = results[0].geometry.location.Ya;
lng = results[0].geometry.location.Za;
该代码可能会中断.
其次,results [0] .geometry.location已经是google.maps.LatLng()对象,因此无需分别提取lat和lng并创建一个新对象.您可以像这样使用它:
map.setCenter(results[0].geometry.location);
var marker = new google.maps.Marker({
id: elemId,
map: map,
position: results[0].geometry.location
})
内容总结
以上是互联网集市为您收集整理的PHP-Google Map API 3标记未显示全部内容,希望文章能够帮你解决PHP-Google Map API 3标记未显示所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。