首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >NativeScript Google-Places >如何使用?

NativeScript Google-Places >如何使用?
EN

Stack Overflow用户
提问于 2018-09-04 13:51:59
回答 2查看 893关注 0票数 0

我正在开发使用Google-Maps-API的应用程序,我想添加使用Google-Places-APIsearch-box字段来自动完成用户到目前为止输入的内容,然后保存所选的项值。

https://github.com/jonny720/do-here-client

所以我得到了我的Google-Places-API密钥,我不知道把它放在哪里,也不知道如何实现这个API。

Google-Maps-API放置在androidMAnifest.xml中,并将其工作良好。

代码语言:javascript
复制
<meta-data
            android:name="com.google.android.geo.API_KEY"
            android:value="@string/nativescript_google_maps_api_key"
            />

现在我实际在哪里实现,我需要在哪里放置密钥呢?

谢谢!

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2018-09-06 11:08:21

好的,这就是我所做的,它起了作用:

我构建了一个PlacesService,代码如下:

代码语言:javascript
复制
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对象,如下所示:

代码语言:javascript
复制
[{"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"}]

但是我该如何分割这个对象呢?我只想使用Namegeometry属性。

谢谢!

票数 0
EN

Stack Overflow用户

发布于 2018-09-05 01:24:48

地点地图-实用程序插件已经可用。你可以用它们。你试过了吗?

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52167924

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档