在Android Google 地图中,如何搜索特定城市内的地址?
In Android Google Map, how do I search address within specific city?
我正在开发一个应用程序,它有一个用于地址搜索的搜索框。我尝试使用下面的 link 但它仅适用于特定国家/地区的结果。
我希望它只搜索特定的城市。
给你。
给它一个地址,它会return给你经纬度。希望这有帮助。
为城市搜索添加这一行
&components=locality:ahmedabad
特定城市内的搜索地址
使用地理编码器
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();
}
我正在开发一个应用程序,它有一个用于地址搜索的搜索框。我尝试使用下面的 link 但它仅适用于特定国家/地区的结果。
我希望它只搜索特定的城市。
给你。
给它一个地址,它会return给你经纬度。希望这有帮助。
为城市搜索添加这一行
&components=locality:ahmedabad
特定城市内的搜索地址
使用地理编码器
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();
}