I'm working on app which uses Google-Maps-API and i want to add search-box
field that uses Google-Places-API to autocomplete what the user typed so far
and then to save the selected item value.
https://github.com/jonny720/do-here-client
So i got my Google-Places-API key, and i don't really know where to put it and how to implement this API.
The Google-Maps-API is placed in the androidMAnifest.xml and its working fine.
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="@string/nativescript_google_maps_api_key"
/>
Now Where do i actually implement the Google-Places-API and where do i need to place the key ?
Thank you !
Ok so this is what i did and it worked:
I build a PlacesService and this is the code :
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);
});
}
Now i'm getting an JSON
object that looks like this :
[{"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"}]
But how do i split this Object ? i want to take only the Name
and the geometry
property.
thank you !