简体   繁体   中英

Android: Google Maps Places API

I am trying to create a fixed filter where I search for specific locations in an area.

So far when I do something like:

Geocoder geocoder = new Geocoder(this);
List<Address> list = geocoder.getFromLocationName("New York", 10);

It returns a location but when I do:

Geocoder geocoder = new Geocoder(this);
List<Address> list = geocoder.getFromLocationName("Hospital", 10);

I get nothing. How would I be able to get those types of searches?

As the documentation says:

getFromLocationName

public List<Address> getFromLocationName (String locationName, 
                int maxResults)

Returns an array of Addresses that are known to describe the named location, which may be a place name such as "Dalvik, Iceland", an address such as "1600 Amphitheatre Parkway, Mountain View, CA", an airport code such as "SFO", etc.. The returned addresses will be localized for the locale provided to this class's constructor.

The query will block and returned values will be obtained by means of a network lookup. The results are a best guess and are not guaranteed to be meaningful or correct. It may be useful to call this method from a thread separate from your primary UI thread.

So, you can't search by confusing location. Hospital is not a location name, so there are no results.

try to use Google Place API, maybe it helps

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM