user1480287
user1480287

Reputation: 31

How to uniquely identify a place on Google Places API

i'm developing a web app that uses the Google Maps JavaScript API v3. I've this problem: I would to save a place in my DB using Places Autocomplete. The user, type a place into a text field and then, after a call vs the API, my application should check if a the city of the selected place exists in my DB; if true, return the city ID, otherwise insert the city and return last inserted ID.

To do this, I need to uniquely identify a place. Any suggestions?

Upvotes: 3

Views: 1753

Answers (1)

sgimeno
sgimeno

Reputation: 1893

EDIT: The PlaceResult given by Places API contains an identifier. You can't use it as a unique id cause it can change as documented here

That's a place result for "London, United Kingdom" from a ES (Spanish) browser:

address_components: Array[4]
formatted_address: "Londres, Reino Unido"
geometry: Object
html_attributions: Array[0]
icon: "http://maps.gstatic.com/mapfiles/place_api/icons/geocode-71.png"
id: "b1a8b96daab5065cf4a08f953e577c34cdf769c0"
name: "Londres"
reference: "CnRmAAAAxcbYEYZvXgbynu4U43cAtEqvCzpZrJUsDusnrYe2pu9nl0zCjyxdeSBMeTVbYQjzaJc56HEyV-YuSJUXLA0sbJUx-1GcaCEFYYX0HSQqXXoId3u_KClG9TpxCUyZhS-dJoLOQj1YJbmPcaWiuFM87hIQGOszWwqjaFe0bseLKvsicRoUCadktNXFFSgNAcHrD8LMSZuXbSA"
types: Array[2]
url: "https://maps.google.com/maps/place?q=Londres&ftid=0x47d8a00baf21de75:0x52963a5addd52a99"
vicinity: "Londres"
__proto__: Object

You should implement some logic to update id's for same place. Haven't found any solution yet for this issue.

Upvotes: 2

Related Questions