Google places api should only return address

I am using 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 only get streets without houses, sometimes I get even cities (if the 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 only want to get streets with houses, because I am writing a taxi and I only need the full address, this is not enough if the user has only selected the street.

So, if I get from Google Proletarsk street 25, Bern, Switzerland

, that's okay, but if I get from Google Proletarsk street, Bern, Switzerland

, that's not okay.

And when I get a response from Google for streets and addresses, it always returns the same type

types =     (
        route,
        geocode
    );

      

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

Can you give me any advice?

+3


source to share


1 answer


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

You should use the geocoding API if you have an address and like Google Maps to parse it for you and return more information. You can determine if the result street_number

is so that you can determine if the result contains a complete address. For example:
https://maps.googleapis.com/maps/api/geocode/json?address=1600+Amphitheater+Parkway,+Mountain+View,+CA
will give you this result:



    {
   "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 gives you street_number

and you can tell it is a complete address.

+1


source







All Articles