如何在不需要提供 HTML 元素的情况下使用其 placeId 获取位置的详细信息?
How to get a location's details using its placeId without needing to supply a HTML element?
我很好奇您如何使用地点的 placeId 获取地点的详细信息,而无需为其提供 HTML 元素。例如,文档 HERE 显示了所有需要 HTML 元素的示例,但我只需要调用它即可在别处使用数据。
var request = {
placeId: 'ChIJN1t_tDeuEmsRUsoyG83frY4'
};
service = new google.maps.places.PlacesService(map);
service.getDetails(request, callback);
function callback(place, status) {
if (status == google.maps.places.PlacesServiceStatus.OK) {
createMarker(place);
}
}
尝试 google 个位置 api https://maps.googleapis.com/maps/api/place/details/json?placeid='PLACE_ID'&key=YOUR KEY'
如果您需要 xml 格式的回复,请将 json 更改为 xml
您可以通过 placeId 获取地点详细信息,除了提供区域内的地点列表外,Places 服务还可以 return 有关特定地点的详细信息。在地点搜索响应中 returned 一个地点后,其地点 ID 可用于请求有关该地点的其他详细信息,例如其完整地址、phone 号码、用户评分和评论等.
地点 ID 提供了一种可靠的方式来引用特定地点的信息。使用地点 ID 的一种常见方法是搜索地点,然后使用 returned 地点 ID 检索地点详细信息。
使用 Google Places API Web 服务,您可以通过执行 Place Search 请求找到地点 ID。
function initMap() {
var map = new google.maps.Map(document.getElementById('map'), {
center: {lat: -33.866, lng: 151.196},
zoom: 15
});
var infowindow = new google.maps.InfoWindow();
var service = new google.maps.places.PlacesService(map);
service.getDetails({
placeId: 'ChIJN1t_tDeuEmsRUsoyG83frY4'
}, function(place, status) {
if (status === google.maps.places.PlacesServiceStatus.OK) {
var marker = new google.maps.Marker({
map: map,
position: place.geometry.location
});
google.maps.event.addListener(marker, 'click', function() {
infowindow.setContent('<div><strong>' + place.name + '</strong><br>' +
'Place ID: ' + place.place_id + '<br>' +
place.formatted_address + '</div>');
infowindow.open(map, this);
});
}
});
我很好奇您如何使用地点的 placeId 获取地点的详细信息,而无需为其提供 HTML 元素。例如,文档 HERE 显示了所有需要 HTML 元素的示例,但我只需要调用它即可在别处使用数据。
var request = {
placeId: 'ChIJN1t_tDeuEmsRUsoyG83frY4'
};
service = new google.maps.places.PlacesService(map);
service.getDetails(request, callback);
function callback(place, status) {
if (status == google.maps.places.PlacesServiceStatus.OK) {
createMarker(place);
}
}
尝试 google 个位置 api https://maps.googleapis.com/maps/api/place/details/json?placeid='PLACE_ID'&key=YOUR KEY'
如果您需要 xml 格式的回复,请将 json 更改为 xml
您可以通过 placeId 获取地点详细信息,除了提供区域内的地点列表外,Places 服务还可以 return 有关特定地点的详细信息。在地点搜索响应中 returned 一个地点后,其地点 ID 可用于请求有关该地点的其他详细信息,例如其完整地址、phone 号码、用户评分和评论等.
地点 ID 提供了一种可靠的方式来引用特定地点的信息。使用地点 ID 的一种常见方法是搜索地点,然后使用 returned 地点 ID 检索地点详细信息。
使用 Google Places API Web 服务,您可以通过执行 Place Search 请求找到地点 ID。
function initMap() {
var map = new google.maps.Map(document.getElementById('map'), {
center: {lat: -33.866, lng: 151.196},
zoom: 15
});
var infowindow = new google.maps.InfoWindow();
var service = new google.maps.places.PlacesService(map);
service.getDetails({
placeId: 'ChIJN1t_tDeuEmsRUsoyG83frY4'
}, function(place, status) {
if (status === google.maps.places.PlacesServiceStatus.OK) {
var marker = new google.maps.Marker({
map: map,
position: place.geometry.location
});
google.maps.event.addListener(marker, 'click', function() {
infowindow.setContent('<div><strong>' + place.name + '</strong><br>' +
'Place ID: ' + place.place_id + '<br>' +
place.formatted_address + '</div>');
infowindow.open(map, this);
});
}
});