Javascript 谷歌地图API v3标记和圆圈突然停止显示
我的地图工作得很好;使用半径圆打印标记,单击时显示信息窗口。然后突然什么都没有了Javascript 谷歌地图API v3标记和圆圈突然停止显示,javascript,google-maps,Javascript,Google Maps,我的地图工作得很好;使用半径圆打印标记,单击时显示信息窗口。然后突然什么都没有了 我浏览了git历史记录,没有对代码进行任何更改 它既不能在本地工作,也不能部署到公共域 没有JS错误 地址的地理编码正确 贴图本身进行渲染 我远低于利率上限 我查看了谷歌地图API变更日志,没有看到任何相关内容 有人请找到我没看到的东西 <!doctype html> <html> <head> <meta charset="utf-8" /&g
- 我浏览了git历史记录,没有对代码进行任何更改李>
- 它既不能在本地工作,也不能部署到公共域
- 没有JS错误
- 地址的地理编码正确
- 贴图本身进行渲染
- 我远低于利率上限
- 我查看了谷歌地图API变更日志,没有看到任何相关内容
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<style>
#map_canvas {
width:1000px;
height:700px;
}
</style>
</head>
<body>
<div id="map_canvas"></div>
<script src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
<script>
var addresses = ["117 Balsam Avenue,Hamilton,Ontario,Canada,L8M 3B4", "47 East Avenue,Hamilton,Ontario,Canada,L8L 5H4"];
var map;
var infoWindow;
function encodeAddresses(addresses, callback) {
var geocoder = new google.maps.Geocoder();
for (var i = 0; i < addresses.length; i++) {
geocoder.geocode({
'address' : addresses[i]
}, function (results, status) {
if (status === google.maps.GeocoderStatus.OK) {
var lat = results[0].geometry.location.Qa;
var long = results[0].geometry.location.Pa;
var address = results[0].formatted_address;
addCircleToMap(lat, long, address);
addMarkerToMap(lat, long, address);
}
});
}
}
function addCircleToMap(lat, long, address) {
var options = {
strokeColor : "#4EA429",
strokeOpacity : 0.8,
strokeWeight : 1,
fillColor : "#4EA429",
fillOpacity : 0.35,
map : map,
center : new google.maps.LatLng(lat, long),
radius : 1000,
address : address
};
var propertyRadius = new google.maps.Circle(options);
google.maps.event.addListener(propertyRadius, 'click', showInfo);
}
function showInfo(e) {
infoWindow.setContent(this.address + "<br />(1000m/3280ft radius)");
infoWindow.setPosition(e.latLng);
infoWindow.open(map);
}
function addMarkerToMap(lat, long, address) {
new google.maps.Marker({
title : address,
map : map,
position : new google.maps.LatLng(lat, long)
});
}
function renderMap() {
var mapContainer = document.getElementById("map_canvas");
var mapOptions = {
zoom : 9,
center : new google.maps.LatLng(43.645004, -79.380707),
mapTypeId : google.maps.MapTypeId.ROADMAP
};
adjustMapContainerHeight(mapContainer);
map = new google.maps.Map(mapContainer, mapOptions);
infoWindow = new google.maps.InfoWindow();
}
function adjustMapContainerHeight(element) {
element.style.height = (document.height - 90) + "px";
}
function getCurrentPosition(defaultLatitude, defaultLongitude, callback) {
var currentPosition = {};
currentPosition.latitude = defaultLatitude;
currentPosition.longitude = defaultLongitude;
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(
function (position) {
currentPosition.latitude = position.coords.latitude;
currentPosition.longitude = position.coords.longitude;
},
function (error) {});
}
callback(currentPosition);
}
getCurrentPosition(43.645004, -79.380707, renderMap);
encodeAddresses(addresses, addCircleToMap);
</script>
</body>
</html>
#地图画布{
宽度:1000px;
高度:700px;
}
var地址=[“加拿大安大略省汉密尔顿市香脂大道117号,L8M 3B4”,“加拿大安大略省汉密尔顿市东大街47号,L8L 5H4”];
var映射;
var信息窗口;
函数编码地址(地址、回调){
var geocoder=new google.maps.geocoder();
对于(变量i=0;i (1000m/3280ft半径)”;
信息窗口。设置位置(如板条);
打开(地图);
}
函数addMarkerToMap(横向、纵向、地址){
新的google.maps.Marker({
标题:地址,
地图:地图,
位置:新google.maps.LatLng(lat,long)
});
}
函数renderMap(){
var mapContainer=document.getElementById(“映射画布”);
变量映射选项={
缩放:9,
中心:新google.maps.LatLng(43.645004,-79.380707),
mapTypeId:google.maps.mapTypeId.ROADMAP
};
调整MapContainerHeight(mapContainer);
map=新的google.maps.map(mapContainer,mapOptions);
infoWindow=new google.maps.infoWindow();
}
功能调整器高度(元件){
element.style.height=(document.height-90)+“px”;
}
函数getCurrentPosition(默认纬度、默认经度、回调){
var currentPosition={};
currentPosition.latitude=默认纬度;
currentPosition.longitude=默认经度;
if(导航器.地理位置){
navigator.geolocation.getCurrentPosition(
职能(职位){
currentPosition.latitude=position.coords.latitude;
currentPosition.longitude=position.coords.longitude;
},
函数(错误){};
}
回调(当前位置);
}
getCurrentPosition(43.645004,-79.380707,renderMap);
编码地址(地址,addCircleToMap);
一次尝试更改encodeAddresses()
函数中的以下行。在我的机器中,更改后可以正常工作:
var lat = results[0].geometry.location.Pa;
var long = results[0].geometry.location.Qa;
您正在使用Pa
作为long
和Qa
作为lat
,这是谷歌不支持的。因此,请更改这两行并检查
希望这对您有所帮助:-)您正在使用未记录的字段,这些字段随API的每个版本而变化 在
LatLng
对象上使用lat()
和lng()
方法
看