我正在开发使用Google-Maps-API的应用程序,我想添加使用Google-Places-API的search-box字段来自动完成用户到目前为止输入的内容,然后保存所选的项值。
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"
/>现在我实际在哪里实现,我需要在哪里放置密钥呢?
谢谢!
发布于 2018-09-06 11:08:21
好的,这就是我所做的,它起了作用:
我构建了一个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属性。
谢谢!
https://stackoverflow.com/questions/52167924
复制相似问题