admin管理员组文章数量:1325720
When using the Google Maps Places API you can create an Autoplete
element attached to a map in order to search their library.
When you select a place you can call autoplete.getPlace()
to retrieve a JSON object describing the place. One field of this is the place_id
, Google's unique reference. Google actually allow these to be stored:
Place IDs are exempt from the caching restrictions stated in Section 10.1.3 of the Google Maps APIs Terms of Service. You can therefore store place ID values indefinitely.
However it's not clear from the documentation how you can use this stored value to retrieve the details of a place. Are there any methods, and how should these be used?
When using the Google Maps Places API you can create an Autoplete
element attached to a map in order to search their library.
When you select a place you can call autoplete.getPlace()
to retrieve a JSON object describing the place. One field of this is the place_id
, Google's unique reference. Google actually allow these to be stored:
Place IDs are exempt from the caching restrictions stated in Section 10.1.3 of the Google Maps APIs Terms of Service. You can therefore store place ID values indefinitely.
However it's not clear from the documentation how you can use this stored value to retrieve the details of a place. Are there any methods, and how should these be used?
Share Improve this question asked Mar 3, 2015 at 17:46 M1keM1ke 6,4064 gold badges35 silver badges52 bronze badges1 Answer
Reset to default 10There is an object in the google.maps.places
namespace called PlacesService
. This has a method called getDetails()
which can accept an ID.
Confusingly the PlacesService
object requires a HTML element to be created. If you just want to use getDetails
you will not need to subsequently use this element, so you can just create one using whatever flavour you prefer - the example below uses jQuery:
var obj=$('<div>').appendTo('body');
var service=new google.maps.places.PlacesService(obj.get(0));
service.getDetails({placeId:''},function(PlaceResult, PlacesServiceStatus){
// PlaceResult is an object
// PlacesServiceStatus is a string
});
Again oddly, the object passed to getDetails
is referred to as a PlaceDetailsRequest
in the documentation, however this class doesn't exist, it's just a description for how the object should be formatted.
版权声明:本文标题:javascript - How do I retrieve place details from the Google Places JS API using a place ID? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742194586a2430840.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论