Google place details street numbers with letters - google-maps

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
}

Related

Google Maps API not returning category from search

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!

Inconsistent language in Google Place Details API

I'm using Google Place Details API on my server to store information about a place, using the placeId sent by a client.
I'm facing an issue regarding the language of the result, which differs when the place is a city or an address in that city, even when the language is specified in the query. For example:
The place id ChIJ53USP0nBhkcRjQ50xhPN_zw is the city of Milan, and the API returns Milan as locality and Lombardy as administrative area (English names)
The place id EjBWaWEgZGVsbGEgU3BpZ2EsIE1pbGFuLCBQcm92aW5jZSBvZiBNaWxhbiwgSXRhbHk is a street in Milan, and the API returns Milano as locality and Lombardia as administrative area (Italian names)
To make it even weirder, both searches return Italy as country. Is this the expected behavior of the API?
Is this the expected behavior of the API?
Yes, this is expected result. Even if you specify a language, it will return the response in that language only if there is one available, if not it will return the response in the language it was originally entered in.
Case 1:
Milan: As a Milan is city. Therefore,there are available results in almost every language. Almost all the major city through out the world have results in every language. By default, you will get result in English.
Case 2:
Via della Spiga: As it is a street. Right now, the results are only available in Italian as they were most possible entered in Italian.
Result when you search "Via della Spiga" in Google Map:
To learn more about this:
Translation of Places information into language specified by request. In this a request for a feature is asked that tells the developer in which language the results are so that they can take care of data accordingly, I personally think that would be great till the issue has not been fixed.
language parameter in place/details request not working
Both of the above issues are about 2 year old. Yet, Google is unable to resolve this issues.
One way to possibly solve this problem is by using textsearch:
As you can convert most of administrative area/city into any language name by using textsearch:
`https://maps.googleapis.com/maps/api/place/textsearch/json?query=Lombardia&lang‌​uage=Your_language&key=YOUR_API_KEY`
Example: Converting "Lombardia" into a chinese language:
https://maps.googleapis.com/maps/api/place/textsearch/json?query=Lombardia&language=zh-CN&key=YOUR_API
{
"html_attributions" : [],
"results" : [
{
"formatted_address" : "意大利伦巴第",
"geometry" : {
"location" : {
"lat" : 45.47906709999999,
"lng" : 9.8452433
},
"viewport" : {
"northeast" : {
"lat" : 46.6351853,
"lng" : 11.4276993
},
"southwest" : {
"lat" : 44.6796491,
"lng" : 8.4978605
}
}
},
"icon" : "http://maps.gstatic.com/mapfiles/place_api/icons/geocode-71.png",
"id" : "02401d0909d69ca5c69de799e193caf84acc41f9",
"name" : "伦巴第",
"place_id" : "ChIJf4M-GsNEgUcR1JMVKCIm8qY",
"reference" : "CoQBfQAAAEKCAV-1Ec-V2ZfnWsCk_elhlEXckc_k94jBYlU7k5ivhrqPlWd24aSAa5fqNTfwKKhU0wSsZFv42aMm1BrG5wEwZNGKwFqELxMEt0ye7KFfBgVtfHZbqeiBx3hEH8Iq60wwW--edqpROkBTjHrxIwisCGJwhCzKKkQ9H6FdfW_aEhAnmI0ZOFk1KGaGms4IqTOiGhRX5iErBIwnmLos4U9Ggs325MmcEA",
"types" : [ "administrative_area_level_1", "political" ]
}
],
"status" : "OK"
}
Lombardia in chinese is 意大利伦巴第
When you search for placeID details, you get address_components array:
"address_components" : [
{
"long_name" : "Via della Spiga",
"short_name" : "Via della Spiga",
"types" : [ "route" ]
},
{
"long_name" : "Milano",
"short_name" : "Milano",
"types" : [ "locality", "political" ]
},
{
"long_name" : "Milano",
"short_name" : "MI",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "Lombardia",
"short_name" : "Lombardia",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "Italy",
"short_name" : "IT",
"types" : [ "country", "political" ]
}
]
So if you loop over the above array and use textsearch then you will get almost consistent address in a particular language.
I think you can use some Optional parameters to set what language you want, such that:
A Nearby Search request is an HTTP URL of the following form:
https://maps.googleapis.com/maps/api/place/nearbysearch/output?parameters
put language parameter, such that:
https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=-33.8670522,151.1957362&radius=500&types=food&name=cruise&language=en
For more detail, please refer here.

How to get JSON from URL in Google App Engine Java

I want to get json from url in google app engine, can u tell me some quite simple methods to do this, thanks, sr my english not good
URL
Content:
{
"debug_info" : [],
"html_attributions" : [ "Listings by \u003ca href=\"http://www.diadiem.com/\"\u003eDiadiem.com\u003c/a\u003e" ],
"next_page_token" : "ClRMAAAAl7MjfntXhFEi33IPPcZJJ5fYfiJzIIGggr9Xc6A_sKeTrjohJntaaG1jWaGYMKiZYruuoqTVipUZFaLhpNXZbhYloN6SeS44epx3lPRdpuMSEHWJTSO2ShwXOz6bjg0xefcaFOUN9wK6NE5Dykjx-x-VLypkBMRH",
"results" : [
{
"geometry" : {
"location" : {
"lat" : 16.058660,
"lng" : 108.2191410
}
},
"icon" : "http://maps.gstatic.com/mapfiles/place_api/icons/generic_business-71.png",
"id" : "7064cb3f44db62207fc2bd83579b63ca9552e658",
"name" : "Vietcombank - Atm",
"reference" : "CnRwAAAAHU3y6j7CocExwcFq6DKtkS2SFT-0X23E7C9M7bpHk2EF04ShIX7IRNl9TwGF_APSwaKmk8XSZIGm52ajXnpKhj15i48w0BHmJR0ZamJdIAi3iJD_sExjjHkf5Lnfxq4iLroTAmQyRAoAVG7dMwVeTRIQcO_Qq9N85d96vQCtEdZjyRoUbETiZPHxkSjkbD9CVnQh6N_8yUA",
"types" : [ "establishment" ],
"vicinity" : "272 Phan Châu Trinh"
},
{
"geometry" : {
"location" : {
"lat" : 16.0602490,
"lng" : 108.21470
}
},
"icon" : "http://maps.gstatic.com/mapfiles/place_api/icons/generic_business-71.png",
"id" : "bd20b9fbd718c13ee3f6d404c3004b649130df4a",
"name" : "ATM DongA Bank",
"reference" : "CnRtAAAAP9XTDfjgtqvahglz24j2posRRCR9ry56xyAd0FX810ZeyiKWeEi4Btfnfycb23Sa6x_grdjJszB7Xf80jFBrer9kHYQHsKX2-spx9LHn_yrZxlfC7wxHOdUt9YbYMp71fzQ_SJOC9W1Hj2cHHi9g0BIQPrdWzJvelD1NDEcC49Q8eRoUE0juanyzeZHjyYbnozUGB13RySk",
"types" : [ "atm", "finance", "establishment" ],
"vicinity" : "Nguyễn Văn Linh, Da Nang"
},
Not sure if I got your question correctly, but if you are trying to parse Google's JSON response, a good and easy way to do it may be to use jQuery parseJSON function.
You can also take a look at this answered question to see sample code.
Also, not explicitly stated in the "answered question" link above - you cannot just access the json (or xml) from within your web page code even though you can use the url manually in a browser to get the json data (as it seems you have done in your post). There are various security aspects and Google will not even send the data requested that way (I believe it is call cross-site-scripting - Google it for more details). It has to go - as in the example linked above, from you web page to your server, have the server do the request to Google to get the data, have the server then post this back to your site/ web page (through AJAX or just a new page - however you are doing things on your site).
That's the sloppy and non-technical, but I wasted all day Sunday trying to get around this until I understood the issue and what I was supposed to (and had to do). This might not be what you are referring to but I think it may indeed be. If so I hope it helps. Cheers

Database Design: saving Google Maps data [closed]

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.

Google Apis Geocode inconsistencies in short_name (same language)

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!