【发布时间】:2021-11-03 20:36:10
【问题描述】:
我想在搜索后滚动到壁橱标记。 Console.log 显示 pin[i] = (50.296322, 9.112082) 和事件 (50.937531, 6.9602786)。 我尝试了很多但总是得到:Cannot read properties of undefined (reading 'spherical')
function geocodeAddress(geocoder, resultsMap){
var address = document.getElementById('address').value;
geocoder.geocode({'address': address}, function(results, status){
if (status === 'OK') {
function find_closest_marker(event){
var distances = [];
var closest = -1;
for(i = 0; i < pins.length; i++){
var d = google.maps.geometry.spherical.computeDistanceBetween(pins[i].position, event);
distances[i] = d;
if (closest == -1 || d < distances[closest]){
closest = i;
}
}
resultsMap.setCenter(pins[closest].position);
}
find_closest_marker(results[0].geometry.location);
} else {
alert('Geocode was not successful for the following reason: ' + status);
}
});
}
【问题讨论】:
-
你没有包含几何库。
-
谢谢您的提示
标签: javascript google-maps google-cloud-platform