我想使用place_id获取地方详情,get_place details 我使用的是Angular_google_map,我使用的是以下代码,但这并没有提供上述详细信息,但我的格式不同。
var map_obj=$scope.map.control.getGMap();
var service = new google.maps.places.PlacesService(map_obj);
$scope.$watch(function() {
return $scope.place_id;
}, function(place_id) {
if (!place_id) {
return;
}
service.getDetails({ placeId: place_id }, function(place, status) {
console.log('place='+place);
$scope.places=place;
});
});
上面的代码提供了以下格式,但我想以不同的格式,请参阅required format,您可以看到几何格式与所需的格式不同。如何获得所需的格式。
Place_format
Object {address_components: Array[5], adr_address: "<span class="extended-address">HSR Layout</span>, …a</span>, <span class="country-name">India</span>", formatted_address: "HSR Layout, Bengaluru, Karnataka, India", geometry: Object, icon: "https://maps.gstatic.com/mapfiles/place_api/icons/geocode-71.png"…}
address_components: Array[5]
adr_address: "<span class="extended-address">HSR Layout</span>, <span class="locality">Bengaluru</span>, <span class="region">Karnataka</span>, <span class="country-name">India</span>"
formatted_address: "HSR Layout, Bengaluru, Karnataka, India"
geometry: Object
location: M
lat: function (){return a}
lng: function (){return b}
__proto__: M
viewport: Pd
__proto__: Object
html_attributions: Array[0]
icon: "https://maps.gstatic.com/mapfiles/place_api/icons/geocode-71.png"
id: "cfeef42cd5db5d4c2a55fc842fcdd712fb1092ad"
name: "HSR Layout"
place_id: "ChIJzW7cv5EUrjsRecj7OYRxMvI"
reference: "CpQBhQAAAC4IfuHnzBloeWfXk8AR4aGPBPIqwAMaIokCX5Ealqo33bGUw5PeRbkUjPvzy_5qqHryCpIz8TSWp0KidBuQ9res84IYoUTnCwlI831HQvHDmPf3uwzui4Bz5GK8mimTPxm4PEOOIpzXpV5ruF9zqJz2L0nMRSuSQJKVcbCSiLOCL4ijmehb5ggm-T5BBkYR6BIQzGX0fHP5x2_7NuUiJMUMFxoUy792_TmWmqOTrImnczW1TIwxwc0"
scope: "GOOGLE"
types: Array[3]
url: "https://maps.google.com/maps/place?q=HSR+Layout,+Bengaluru,+Karnataka,+India&ftid=0x3bae1491bfdc6ecd:0xf232718439fbc879"
vicinity: "HSR Layout"
__proto__: Object
答案 0 :(得分:0)
我在尝试这样做时也遇到了麻烦,我只是想通了。最简单的方法是使用PlaceService的实例:
var placesService = new google.maps.places.PlacesService(map);
placesService.getDetails(
{placeId: 'reallylongstringgoeshere'},
function(results, status) {
console.log(status);
console.log(results);
}
);