2

我想使用place_id獲取地點詳細信息,get_place details 我正在使用Angular_google_map,我正在使用以下代碼,但這並沒有提供如上所述的地方詳細信息,但我得到了不同的格式。如何使用place_id獲取地點詳情?

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

對不起,我不明白這個問題,但我希望這些信息有幫助:有關使用「PlacesService.getDetails」的示例,請參閱https://developers.google.com/maps/documentation/javascript/examples/放置的詳細信息。 https://developers.google.com/maps/documentation/javascript/reference#PlaceGeometry記錄了'PlaceResult'對象的'geometry'屬性。 – spiv

+0

[使用json和placeid的Google地圖上的多個標記]的可能重複(http://stackoverflow.com/questions/31804984/multiple-markers-on-google-maps-using-json-and-placeid) – geocodezip

回答

0

我遇到了麻煩試圖做到這一點也和我想通了。最簡單的方法是使用PlaceService的一個實例:

var placesService = new google.maps.places.PlacesService(map); 

placesService.getDetails(
    {placeId: 'reallylongstringgoeshere'}, 
    function(results, status) { 
     console.log(status); 
     console.log(results); 
    } 
); 

檢出their docs with an example

相關問題