在Android Google Map中,如何搜索特定城市内的地址?

时间:2016-07-08 11:45:04

标签: android google-maps google-geocoding-api city

我正在开发一个具有地址搜索搜索框的应用程序。我试图使用以下链接,但它仅适用于特定国家/地区的结果。

A link for address search

我希望它只搜索特定的城市。

3 个答案:

答案 0 :(得分:1)

你走了。

给它一个地址,它将为你返回纬度和经度。希望这会有所帮助。

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

答案 1 :(得分:1)

为城市搜索添加此行

&components=locality:ahmedabad

特定城市内的搜索地址

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

答案 2 :(得分:0)

使用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();
            }
相关问题