【发布时间】:2016-10-02 06:09:49
【问题描述】:
我目前正在尝试使用 Google Geocoder API 将地址转换为 Lat/Lng 坐标,但是,在使用他们的开发文档 (https://developers.google.com/maps/documentation/javascript/geocoding) 上的示例时,我遇到了“InvalidValueError:未知属性”错误函数”
在我的 HTML 文件中,我调用了谷歌地图 API 和地图 div,我的地图应该在其中呈现。 (当然我也有其他的东西,但为了直截了当,我只会贴出相关代码)
<script src="https://maps.googleapis.com/maps/api/js?key=APIKEY&callback=initMap" async defer></script>
<div id="map"></div>
在我的 JS 文件中:
window.initMap = function(){
var fromLocation = new google.maps.LatLng(37.09024, -95.712891),
destLocation = new google.maps.LatLng(37.09024, -95.712891),
map = new google.maps.Map(document.getElementById('map'), {
center: {lat: 37.09024 , lng: -95.712891}, // center of USA
zoom: 4 // continet level
}),
directionService = new google.maps.DirectionsService(),
directionRender = new google.maps.DirectionsRenderer({
map: map
}),
markerA = new google.maps.Marker({
position: fromLocation,
title: "Point A",
label: "From",
map:map
}),
markerB = new google.maps.Marker({
position: destLocation,
title: "Point B",
label:"Destination",
map:map
});
getLatLng("Los Angeles");
} // end of initMap
function getLatLng(address){
geocoder = new google.maps.Geocoder();
geocoder.geocode({address: address, function(results,status){
if(status === 'OK'){
console.log(results[0].geometry.location);
}
else{
console.log("Geocoding couldn't convert string address to lat/long points");
}
}
});// end of geocoder method.
}
关于如何修复未知属性函数错误的任何想法? 谢谢!
【问题讨论】:
标签: javascript html google-maps google-maps-api-3