【问题标题】:NativeScript Google-Places API --> how to use?NativeScript Google-Places API --> 如何使用?
【发布时间】:2018-09-04 13:51:59
【问题描述】:

我正在开发使用 Google-Maps-API 的应用程序,我想添加使用 Google-Places-APIsearch-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"
            />

现在我在哪里实际实现 Google-Places-API 以及我需要在哪里放置密钥?

谢谢!

【问题讨论】:

    标签: google-maps google-places-api nativescript search-box


    【解决方案1】:

    PlacesMaps-utils 插件已经可用。你可以使用它们。你试过了吗?

    【讨论】:

    【解决方案2】:

    好的,这就是我所做的并且成功了:

    我构建了一个 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"}]
    

    但是我如何分割这个对象?我只想获取Namegeometry 属性。

    谢谢!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-15
      • 1970-01-01
      • 2018-07-08
      • 2015-03-18
      • 2016-04-07
      相关资源
      最近更新 更多