android_griezmann
android_griezmann

Reputation: 3887

In Android Google Map, how do I search address within specific city?

I am developing an app which is having a search box for address search. I have tried to use below link but it's only for country specific results.

A link for address search

I want it to search only specific city.

Upvotes: 0

Views: 2043

Answers (3)

Gugelhupf
Gugelhupf

Reputation: 970

Use GeoCoder

import android.location.Address;
import android.location.Geocoder;
import android.location.Location;

 Geocoder geoCoder = new Geocoder(Injector.INSTANCE.getApplicationComponent().applicationContext(), Locale.getDefault());
            try {
                List<Address> addresses = geoCoder.getFromLocationName(
                        "City name", 5);

                if (addresses.size() > 0) {
                    Log.d(TAG,"ADRESSE "+ addresses.get(0) +",LAT :" + addresses.get(0).getLatitude() +", LONG :" + addresses.get(0).getLongitude() );
                }
            } catch (IOException e) {
                e.printStackTrace();
            }

Upvotes: -1

comeback4you
comeback4you

Reputation: 716

add this line for city search

&components=locality:ahmedabad

search address within specific city

http://maps.googleapis.com/maps/api/geocode/json?address=Singapore%20505468&sensor=true&components=locality:ahmedabad

Upvotes: 1

GyroCocoa
GyroCocoa

Reputation: 1612

Here you go.

Give it an address and it will return the latitude and longitude to you. Hope this helps.

http://code.google.com/apis/maps/documentation/geocoding/

Upvotes: 1

Related Questions