Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google places api should return only address

I use this url to get addresses with Get request: https://maps.googleapis.com/maps/api/place/autocomplete/json?input=Nov&key=MyKet&types=address

But sometimes I get only streets without houses, sometimes I get even cities (if input=Minsk in Russian: https://maps.googleapis.com/maps/api/place/autocomplete/json?input=%D0%9C%D0%98%D0%9D%D0%A1%D0%9A&key=MyKey&types=address)

But I want to get only streets with houses, because I'm writing taxi application and I need there only full address, it's not enough if user selected only street.

So if I get from Google Proletarsk street 25, Bern, Switzerland - it's ok, but if I get from Google Proletarsk street, Bern, Switzerland - it's not ok.

And when I get the responce from Google for streets and addresses it always return the same type

types =     (
        route,
        geocode
    );

So I can't even differ if the return value is a street or if it's a full address.

Can you give me any advice?

like image 248
Paul T. Avatar asked Oct 31 '22 00:10

Paul T.


1 Answers

Based on the use case you describe, it sounds like you used the wrong API.

You should be using the Geocoding API if you have the address and would love Google Maps parse it for you and return extra information. You can determine if the result has a street_number so that you can tell if the result contains a full address. For example:
https://maps.googleapis.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA
would give you a result like this:

    {
   "results" : [
      {
         "address_components" : [
            {
               "long_name" : "1600",
               "short_name" : "1600",
               "types" : [ "street_number" ]
            },
            {
               "long_name" : "Amphitheatre Parkway",
               "short_name" : "Amphitheatre Pkwy",
               "types" : [ "route" ]
            },
            {
               "long_name" : "Mountain View",
               "short_name" : "Mountain View",
               "types" : [ "locality", "political" ]
            },
            {
               "long_name" : "Santa Clara County",
               "short_name" : "Santa Clara County",
               "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" ]
            }
         ],
         "formatted_address" : "1600 Amphitheatre Parkway, Mountain View, CA 94043, USA",
         "geometry" : {
            "location" : {
               "lat" : 37.4223455,
               "lng" : -122.0841893
            },
            "location_type" : "ROOFTOP",
            "viewp.....

Which give you a street_number and so you can tell it is a full address.

like image 125
kaho Avatar answered Nov 15 '22 05:11

kaho