NativeScript Google-Places API --> 怎么用?
NativeScript Google-Places API --> how to use?
我正在开发使用 Google-Maps-API 的应用,我想添加 search-box
使用 Google-Places-API 自动完成用户目前输入的内容
然后保存选中的项目值。
https://github.com/jonny720/do-here-client
所以我得到了我的 Google-Places-API 密钥,但我真的不知道把它放在哪里以及如何实现它API.
Google-Maps-API放在androidMAnifest.xml及其工作正常。
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="@string/nativescript_google_maps_api_key"
/>
现在我实际上在哪里实现 Google-Places-API 以及我需要在哪里放置密钥?
谢谢!
Places and Maps-utils 插件已经可用。你可以使用它们。你试过了吗?
好的,这就是我所做的并且有效:
我构建了一个 PlacesService,这是代码:
autoCompleteUrl = 'https://maps.googleapis.com/maps/api/place/autocomplete/xml?input=';
autoCompleteUrl2 = '&key=API_KEY'
urlReq='https://maps.googleapis.com/maps/api/place/findplacefromtext/json?input=';
urlreq2 = '&inputtype=textquery&fields=formatted_address,name,geometry&key=API_KEY'
newPlace: any;
constructor(private http :HttpClient){}
auto(typed):any{
if (typed){
console.log("got to func",typed)
return this.http.get(this.autoCompleteUrl+typed+this.autoCompleteUrl2);
}
}
findPlace(place):any {
// return this.http.get(this.urlReq+place+this.urlreq2);
this.http.get(this.urlReq+place+this.urlreq2)
.toPromise().then(res => {
this.newPlace = JSON.stringify(res);
console.log("#########", this.newPlace);
});
}
现在我得到一个看起来像这样的 JSON
对象:
[{"candidates":[{"formatted_address":"United States","geometry":{"location":{"lat":37.09024,"lng":-95.712891},"viewport":{"northeast":{"lat":49.38,"lng":-66.94},"southwest":{"lat":25.82,"lng":-124.39}}},"name":"United States"}],"debug_log":{"line":[]},"status":"OK"}, {"candidates":[{"formatted_address":"United States","geometry":{"location":{"lat":37.09024,"lng":-95.712891},"viewport":{"northeast":{"lat":49.38,"lng":-66.94},"southwest":{"lat":25.82,"lng":-124.39}}},"name":"United States"}],"debug_log":{"line":[]},"status":"OK"}]
但是我该如何拆分这个对象呢?我只想拿 Name
和 geometry
属性.
谢谢!
我正在开发使用 Google-Maps-API 的应用,我想添加 search-box
使用 Google-Places-API 自动完成用户目前输入的内容
然后保存选中的项目值。
https://github.com/jonny720/do-here-client
所以我得到了我的 Google-Places-API 密钥,但我真的不知道把它放在哪里以及如何实现它API.
Google-Maps-API放在androidMAnifest.xml及其工作正常。
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="@string/nativescript_google_maps_api_key"
/>
现在我实际上在哪里实现 Google-Places-API 以及我需要在哪里放置密钥?
谢谢!
Places and Maps-utils 插件已经可用。你可以使用它们。你试过了吗?
好的,这就是我所做的并且有效:
我构建了一个 PlacesService,这是代码:
autoCompleteUrl = 'https://maps.googleapis.com/maps/api/place/autocomplete/xml?input=';
autoCompleteUrl2 = '&key=API_KEY'
urlReq='https://maps.googleapis.com/maps/api/place/findplacefromtext/json?input=';
urlreq2 = '&inputtype=textquery&fields=formatted_address,name,geometry&key=API_KEY'
newPlace: any;
constructor(private http :HttpClient){}
auto(typed):any{
if (typed){
console.log("got to func",typed)
return this.http.get(this.autoCompleteUrl+typed+this.autoCompleteUrl2);
}
}
findPlace(place):any {
// return this.http.get(this.urlReq+place+this.urlreq2);
this.http.get(this.urlReq+place+this.urlreq2)
.toPromise().then(res => {
this.newPlace = JSON.stringify(res);
console.log("#########", this.newPlace);
});
}
现在我得到一个看起来像这样的 JSON
对象:
[{"candidates":[{"formatted_address":"United States","geometry":{"location":{"lat":37.09024,"lng":-95.712891},"viewport":{"northeast":{"lat":49.38,"lng":-66.94},"southwest":{"lat":25.82,"lng":-124.39}}},"name":"United States"}],"debug_log":{"line":[]},"status":"OK"}, {"candidates":[{"formatted_address":"United States","geometry":{"location":{"lat":37.09024,"lng":-95.712891},"viewport":{"northeast":{"lat":49.38,"lng":-66.94},"southwest":{"lat":25.82,"lng":-124.39}}},"name":"United States"}],"debug_log":{"line":[]},"status":"OK"}]
但是我该如何拆分这个对象呢?我只想拿 Name
和 geometry
属性.
谢谢!