gpt4 book ai didi

javascript - Google map JavaScript-地点详细信息结果

转载 作者:行者123 更新时间:2023-12-03 11:25:09 24 4
gpt4 key购买 nike

下面的代码中,place.name 显示通过地理位置找到的地点的名称。我应该能够使用 place.formatted_address 列出地址,但这不起作用。我错过了什么?

https://developers.google.com/maps/documentation/javascript/places?csw=1#place_details_requests

 <script src="https://maps.googleapis.com/maps/api/js?libraries=places"></script>
<script>

var map, placesList;

function initialize() {
var pyrmont = new google.maps.LatLng(40.062664, -83.069101);

map = new google.maps.Map(document.getElementById('map-canvas'), {
center: pyrmont,
zoom: 17
});

var request = {
location: pyrmont,
radius: 500,
types: ['store']
};

placesList = document.getElementById('places');

var service = new google.maps.places.PlacesService(map);
service.nearbySearch(request, callback);
}

function callback(results, status, pagination) {
if (status != google.maps.places.PlacesServiceStatus.OK) {
return;
} else {
createMarkers(results);

if (pagination.hasNextPage) {
var moreButton = document.getElementById('more');

moreButton.disabled = false;

google.maps.event.addDomListenerOnce(moreButton, 'click',
function() {
moreButton.disabled = true;
pagination.nextPage();
});
}
}
}

function createMarkers(places) {
var bounds = new google.maps.LatLngBounds();

for (var i = 0, place; place = places[i]; i++) {
var image = {
url: place.icon,
size: new google.maps.Size(71, 71),
origin: new google.maps.Point(0, 0),
anchor: new google.maps.Point(17, 34),
scaledSize: new google.maps.Size(25, 25)
};

var marker = new google.maps.Marker({
map: map,
icon: image,
title: place.name,
phone:place.formatted_address,
position: place.geometry.location
});

placesList.innerHTML += '<li>' + place.name + '</li>';
placesList.innerHTML += '<li>' + place.formatted_address + '</li>';
bounds.extend(place.geometry.location);
}
map.fitBounds(bounds);
}

google.maps.event.addDomListener(window, 'load', initialize);

</script>

最佳答案

您不需要请求地点详细信息,而是运行nearbySearch

据记录search-response将仅包含 textSearch

formatted_address 属性

关于javascript - Google map JavaScript-地点详细信息结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26953599/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com