I'm using Google API Geocodes to retrieve the administratives levels from an address given. If I try with Valladolid, Spain ( http://maps.google.com/maps/api/geocode/json?sensor=false&address=Valladolid,Spain&language=en ) I get as administrative_area_level_2.short_name: VA.
{
"long_name": "Valladolid",
"short_name": "VA",
"types": [
"administrative_area_level_2",
"political"
]
},
But if I try with Seville,Spain ( http://maps.google.com/maps/api/geocode/json?sensor=false&address=Seville,Spain&language=en ) :
{
"long_name": "Seville",
"short_name": "Seville",
"types": [
"administrative_area_level_2",
"political"
]
},
the short name is Seville instead of SE.
Anybody knows how to skip this problem? I'm working with severals countries and some of them have this problem.
Thanks in advance.
I cannot say certainly, but this might be a data issue on the Google side. I suppose the administrative area level 2 for Valladolid has an abbreviated value stored in the database while administrative area level 2 for Sevilla doesn't have the abbreviated value stored, so Geocoding API uses the complete name.
You should send a feedback to Google. Open the Sevilla admin area level 2 in Google maps
https://www.google.com/maps/place/Seville/#37.5145054,-6.7170897,8z/data=!3m1!4b1!4m5!3m4!1s0xd12f2dae16bd169:0x30463fd8c9fcbc0!8m2!3d37.3376829!4d-5.5617279
and click Send feedback as shown in my screenshot
I hope this helps!
Related
I am trying to return the category or types from google maps api but getting inconsistent results.
The below shows correct types for 'lowes'.
https://maps.googleapis.com/maps/api/place/findplacefromtext/json?input=lowes&inputtype=textquery&fields=formatted_address,name,types&key=API_KEY
"types" : [
"hardware_store",
"furniture_store",
"home_goods_store",
"point_of_interest",
"store",
"establishment"
However, when I try something like the below...
https://maps.googleapis.com/maps/api/place/findplacefromtext/json?input=Alaska%20Railroad%20Bogard&inputtype=textquery&fields=formatted_address,name,types&key=API_KEY
I get ...
"types" : [ "point_of_interest", "establishment" ]
But when i just go to googlemaps.com and search for 'Alaska Railroad Bogard' I get the type or category as 'Railroad Company'
I am looking to return 'Railroad Company'
Hope someone can help!
When I do search in google's autocomplete I see correct address. Example:
Pavlichenko Street, 20b, Bila Tserkva, Kyiv Oblast, Ukraine
This address has place_id:
EjtQYXZsaWNoZW5rbyBTdHJlZXQsIDIwYiwgQmlsYSBUc2Vya3ZhLCBLeWl2IE9ibGFzdCwgVWtyYWluZSIwEi4KFAoSCVcssl0EQtNAEeDmEfl02RgXEBQqFAoSCVGxb54DQtNAEbhYfU4LYvbk
I need to get a street number which is "20b". To do so I use Place Details API:
https://maps.googleapis.com/maps/api/place/details/json?placeid=EjtQYXZsaWNoZW5rbyBTdHJlZXQsIDIwYiwgQmlsYSBUc2Vya3ZhLCBLeWl2IE9ibGFzdCwgVWtyYWluZSIwEi4KFAoSCVcssl0EQtNAEeDmEfl02RgXEBQqFAoSCVGxb54DQtNAEbhYfU4LYvbk&key=MY_KEY
And here what is in response:
"address_components" : [
{
"long_name" : "20",
"short_name" : "20",
"types" : [ "street_number" ]
},
{
"long_name" : "Pavlichenko Street",
"short_name" : "Pavlichenko Street",
"types" : [ "route" ]
},
{
"long_name" : "Bila Tserkva",
"short_name" : "Bila Tserkva",
"types" : [ "locality", "political" ]
...
But "20" is actually different house, I need "20b". Same happens to all streets with letters. Is there way to solve this problem? Thank you
The long place ID EjtQYXZsaWNoZW5rbyBTdHJlZXQsIDIwYiwgQmlsYSBUc2Vya3ZhLCBLeWl2IE9ibGFzdCwgVWtyYWluZSIwEi4KFAoSCVcssl0EQtNAEeDmEfl02RgXEBQqFAoSCVGxb54DQtNAEbhYfU4LYvbk indicates that this address is not present in Google database. They try to interpolate it to the best known position that matches your search.
Note that the existing in database addresses have a short place IDs, something like ChIJNSfioSOjpBIRSwaYW7O3LJY.
Your prediction has a following type
"types":[
"route","geocode"
]
So it looks like Google could resolve it to route level, but not to street address level.
I can suggest reporting a missing address to Google data team as explained in the documentation
https://support.google.com/maps/answer/3094088
I hope this addresses your doubt.
In case it helps someone, we use a regex to check whether a street number is of a "special" format, e.g. 3a, or even 3/24, both of which are reduced to just "3" by Google.
We use the "formatted" address as a reference check. Feel free to modify to match your needs:
parseStreetNumber(streetNumber, formatted) {
//Handle a format like 23/241 or 3a, which Google strips
const regex = new RegExp(`^([0-9a-z]+/${streetNumber}|${streetNumber}[a-z])`, 'i')
const matches = formatted.match(regex)
if (matches) {
return matches[1]
}
//Return as is
return streetNumber
}
Given the following API call to autocomplete:
https://maps.googleapis.com/maps/api/place/autocomplete/json?types=address&input=23%20norton%20st
I get the following response:
{
"predictions": [
{
"description": "23 Norton Street, Leichhardt, New South Wales, Australia",
"id": "9711c656faa60f77a05680b603523a4bc75c45be",
"place_id": "EjgyMyBOb3J0b24gU3RyZWV0LCBMZWljaGhhcmR0LCBOZXcgU291dGggV2FsZXMsIEF1c3RyYWxpYQ",
"types": [
"route",
"geocode"
]
},
...
],
"status": "OK"
}
Notice the types are of route and geocode.
If I query the detail API:
https://maps.googleapis.com/maps/api/place/details/json?placeid=EjgyMyBOb3J0b24gU3RyZWV0LCBMZWljaGhhcmR0LCBOZXcgU291dGggV2FsZXMsIEF1c3RyYWxpYQ
I get the following:
{
"html_attributions": [],
"result": {
"id": "e698fdcd9dceed8fe42a926a19cb2b17d4f5f088",
"name": "23 Norton St",
"place_id": "ChIJpdXOTxewEmsRMmpMxLBgFpI",
"reference": "CmRbAAAAKmYoyR1BrFqFQJi6CAD8cjhD4SDnZXMIC0mOLOpX_jPgIgFv0TJ3rv8p5L9xKrplHzUFxBNc8sd7PdkXdnCsTo_7-3X7mocd8yHnXCIKYAxj0MO4icLoFJjD3DEszqK3EhD8XIu6zNH-h3hqotfKjmd-GhRwyNIfJCo4bmOOLYgubm7j8ln_tw",
"scope": "GOOGLE",
"types": [
"street_address"
],
"url": "https://maps.google.com/?q=23+Norton+St,+Leichhardt+NSW+2040,+Australia&ftid=0x6b12b0174fced5a5:0x921660b0c44c6a32",
"utc_offset": 600,
"vicinity": "Leichhardt"
},
"status": "OK"
}
The types and the place id are different from the first response. I would expect them to be the same, why are they different?
If you do the search for "23 Norton Street" rather than "23 Norton St" you actually get the results you'd expect (matching place_id, type etc). I think what is happening is that when you search for 23 Norton St it doesn't actually have a match (as St rather than Street) and so it performs a geocode lookup, and that's the result you see.
Is there any reason the result is causing problems for you? Or is it just an oddity/curiosity?
Not sure what your actual issue is, but it is possible for Google Places to actually have multiple IDs for one location. Reference: https://developers.google.com/places/place-id
Also it seems you may have your AutoComplete setup to only provide you back types regarding geocode and route as that is also an option for results. It's unknown without your actual code.
I'm sure you have been to the documentation here: https://developers.google.com/maps/documentation/javascript/examples/places-autocomplete
but maybe you missed something in the example there. Hope that answers your 'question'!
I am trying to make an application which will let the users search nearby vendors. For that, each vendor registration form will have a textbox where a Vendor can put his address. As I don't have the list of localities to validate against, I am trying to use Googe Places API for locality suggestion.
The locality suggestion textbox in the Vendor registration form will look like the image below:
locality suggestion textbox in the vendor registration form
The user interface to choose the location will look like the image below:
user interface to choose the location
After the locality selection, the user should see only nearby Vendors. The response of the google places API is
{
"html_attributions": [],
"results": [
{
"formatted_address": "Motera, Ahmedabad, Gujarat, India",
"geometry": {
"location": {
"lat": 23.1036054,
"lng": 72.6024044
},
"viewport": {
"northeast": {
"lat": 23.112303,
"lng": 72.611829
},
"southwest": {
"lat": 23.0824881,
"lng": 72.5931459
}
}
},
"icon": "https://maps.gstatic.com/mapfiles/place_api/icons/geocode-71.png",
"id": "beb375b14ad845f8a22e69c93617bee0256678b9",
"name": "Motera",
"photos": [
{
"height": 768,
"html_attributions": [
"Denny 00_"
],
"photo_reference": "CoQBdwAAADhFAFfh71z9-Ezw2FMPN-dfmbVDhp8LFJLVmipB_uiK57ZIHWX9vL6UBxotMee794LGmWy_us0RDS521rblsBJgEWL7Wzmg2_Ni9bVfvRJfE6Cb_wf9hzZqvdQUTozVP5z8FaItU-RHjv7Sz92f_ACk8_CpUsEGfeRHF13uI8j5EhDIB0RXJxrzsLVhUImoqMruGhTvq6O1_ZsOWOJslKCSVsXiU_0_gQ",
"width": 1280
}
],
"place_id": "ChIJTxIjdsODXjkRiCMOQDvxt24",
"reference": "CmRbAAAAfxr_8ylDJoydKhrJFZMQVaziF5T89c-KwrgI95qWKqlwcZddHbuAryoaYMq1Qd17v8d0l9SwM47hwuBiuzPOTAb_9tKYS_0K575oUnMIylmG48cBjzQaDzNbsNOIxPFuEhB3MNrFc3saxfKwtfVGWgbEGhTtyA6ohpXeHhwLQ42PjOiIEOkPxw",
"types": [
"sublocality_level_1",
"sublocality",
"political"
]
}
],
"status": "OK"
}
What should I store in the database from above response so that I can filter records by location? I can split the "formatted_address" key into three and store them in three separate fields in Vendor registration table. But that will be redundant. Or I can store the area, city and state in three separate table and reference the ID. But this seems to be too much work? What is the best way to handle this?
Also, does google allow storing the response data?
You need the geographic coordinates if you want to find "nearby" locations by querying your database.
Last I looked at the Places API TOU, the only data you are allowed to store persistently is the placeId.
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 11 years ago.
SEE: http://maps.googleapis.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&sensor=false
I'm using MySQL.
Given a partial or complete address, the Google Map API will return something like this:
"address_components" : [
{
"long_name" : "1600",
"short_name" : "1600",
"types" : [ "street_number" ]
},
{
"long_name" : "Amphitheatre Pkwy",
"short_name" : "Amphitheatre Pkwy",
"types" : [ "route" ]
},
{
"long_name" : "Mountain View",
"short_name" : "Mountain View",
"types" : [ "locality", "political" ]
},
{
"long_name" : "Santa Clara",
"short_name" : "Santa Clara",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "California",
"short_name" : "CA",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "United States",
"short_name" : "US",
"types" : [ "country", "political" ]
},
{
"long_name" : "94043",
"short_name" : "94043",
"types" : [ "postal_code" ]
}
]
Assume I am developing an application wherein:
account owners can specify their location, and
search by location is supported
How should I store the address components I get from Google so that I can query for the following:
How many account owners in a particular country?
How many account owners in a particular state?
How many account owners in a particular ZIP/postal code?
etc.
One very easy way is to store individual address components in one table:
TABLE: account
- account_id (PK)
- street_number
- route
- locality
- administrative_area_level_2
- administrative_area_level_1
- country
- postal_code
I'll just leave blank whatever information Google does not provide (e.g. if account owner did not provide a street number, then the Google API also won't return the street_number). I think this would be the simplest to query. However, this data won't be normalized.
Alternatively, I could could design the database to have multiple tables, for example:
TABLE: country
- country_id (PK)
- name
TABLE: administrative_area_level_1
- administrative_area_level_1_id (PK)
- country_id (FK)
- name
... and so on
This will probably normalize the data, but might be a pain to query. Also, missing information might also cause some problems. For example, what if Google returns country and administrative_area_level_2, skipping administrative_area_level_1 (I'm not sure if this is even possible)? administrative_area_level_2 would require a administrative_area_level_1_id as its FK -- and without it, the model breaks.
Another idea might be to use a nested set or adjacency model. The data would be normalized and would probably be able to deal better with missing information.
My gut feeling is that the simplest model -- the one allowing redundant data -- is the best option for me. The data is not coming from me, it's coming from Google and I think I only need the data so I can do these search-by-location searches. Maybe I won't run into anomalies?
Any suggestions on how to model this?
Before you start worrying about how to model the data you retrieve from Google Maps, you might want to check out the terms of service first, at http://code.google.com/apis/maps/terms.html.
Particularly take note of 10.1.3 (a):
"You must not copy, translate, modify, or create a derivative work (including creating or contributing to a database) of, or publicly display any Content or any part thereof..."
I'd say that pretty much explicitly prohibits the kind of application you're trying to build. If you want to query the address information Google has about one of your account owners, you have to do it using Google's APIs - not copying their data and doing it in your own application.