本文整理汇总了Java中android.location.Geocoder.getFromLocation方法的典型用法代码示例。如果您正苦于以下问题:Java Geocoder.getFromLocation方法的具体用法?Java Geocoder.getFromLocation怎么用?Java Geocoder.getFromLocation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.location.Geocoder
的用法示例。
在下文中一共展示了Geocoder.getFromLocation方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getAddress
import android.location.Geocoder; //导入方法依赖的package包/类
public String getAddress(Context context, double lat, double lng) {
Geocoder geocoder = new Geocoder(context, Locale.getDefault());
try {
List<Address> addresses = geocoder.getFromLocation(lat, lng, 1);
Address obj = addresses.get(0);
String add = obj.getAddressLine(0);
add = add + "," + obj.getAdminArea();
add = add + "," + obj.getCountryName();
return add;
} catch (IOException e) {
e.printStackTrace();
Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show();
return null;
}
}
示例2: getGeocoderAddress
import android.location.Geocoder; //导入方法依赖的package包/类
public List<Address> getGeocoderAddress(Context context)
{
if (location != null)
{
Geocoder geocoder = new Geocoder(context, Locale.ENGLISH);
try
{
List<Address> addresses = geocoder.getFromLocation(latitude, longitude, 1);
return addresses;
}
catch (IOException e)
{
//e.printStackTrace();
Log.e("Error : Geocoder", "Impossible to connect to Geocoder", e);
}
}
return null;
}
示例3: setRegistrationLocation
import android.location.Geocoder; //导入方法依赖的package包/类
public void setRegistrationLocation(Intent data) {
final Place place = PlacePicker.getPlace(getActivity(), data);
Geocoder geocoder = new Geocoder(getActivity());
try {
List<Address> addresses = geocoder.getFromLocation(place.getLatLng().latitude, place.getLatLng().longitude, 1);
elephant.registrationLoc.cityName = addresses.get(0).getAddressLine(0);
if (!addresses.get(0).getAddressLine(0).equals(addresses.get(0).getSubAdminArea())) {
elephant.registrationLoc.districtName = addresses.get(0).getSubAdminArea();
}
elephant.registrationLoc.provinceName = addresses.get(0).getAdminArea();
} catch (IOException e) {
e.printStackTrace();
}
registrationLocation.setText(elephant.registrationLoc.format());
}
示例4: getLocalityNameEng
import android.location.Geocoder; //导入方法依赖的package包/类
public static String getLocalityNameEng(Context context, LatLng latLng) {
Geocoder gcd = new Geocoder(context, Locale.US);
try {
List<Address> addresses = gcd.getFromLocation(latLng.latitude, latLng.longitude, 1);
if (addresses.size() > 0) {
Address address = addresses.get(0);
String name = address.getCountryName();
if (address.getLocality() != null)
name = address.getLocality();
return name;
}
} catch (IOException ex) {
Log.d(TAG, Log.getStackTraceString(ex));
}
return null;
}
示例5: setBirthLocation
import android.location.Geocoder; //导入方法依赖的package包/类
/**
* Set birth location from map
*
* @param location the location returned from the map picker
*/
public void setBirthLocation(Intent data) {
final Place place = PlacePicker.getPlace(getActivity(), data);
Geocoder geocoder = new Geocoder(getActivity());
try {
List<Address> addresses = geocoder.getFromLocation(place.getLatLng().latitude, place.getLatLng().longitude, 1);
elephant.birthLoc.cityName = addresses.get(0).getAddressLine(0);
if (!addresses.get(0).getAddressLine(0).equals(addresses.get(0).getSubAdminArea())) {
elephant.birthLoc.districtName = addresses.get(0).getSubAdminArea();
}
elephant.birthLoc.provinceName = addresses.get(0).getAdminArea();
} catch (IOException e) {
e.printStackTrace();
}
birthLocation.setText(elephant.birthLoc.format());
}
示例6: getAddressFromLocation
import android.location.Geocoder; //导入方法依赖的package包/类
public Address getAddressFromLocation(final double latitude, final double longitude,
final Context context) {
Geocoder geocoder = new Geocoder(context, Locale.getDefault());
try {
List<Address> addressList = geocoder.getFromLocation(
latitude, longitude, 1);
if (addressList != null && addressList.size() > 0) {
address = addressList.get(0);
}
} catch (IOException e) {
Log.e(TAG, "Unable connect to Geocoder", e);
}
return address;
}
示例7: updateMemoryPosition
import android.location.Geocoder; //导入方法依赖的package包/类
private void updateMemoryPosition(Memory memory, LatLng latLng) {
Geocoder geocoder = new Geocoder(this);
List<Address> matches = null;
try {
matches = geocoder.getFromLocation(latLng.latitude, latLng.longitude, 1);
} catch (IOException e) {
e.printStackTrace();
}
Address bestMatch = (matches.isEmpty()) ? null : matches.get(0);
int maxLine = bestMatch.getMaxAddressLineIndex();
memory.city = bestMatch.getAddressLine(maxLine - 1);
memory.country = bestMatch.getAddressLine(maxLine);
memory.latitude = latLng.latitude;
memory.longitude = latLng.longitude;
}
示例8: getGeocoderAddress
import android.location.Geocoder; //导入方法依赖的package包/类
/**
* Get list of address by latitude and longitude
* @return null or List<Address>
*/
public List<Address> getGeocoderAddress(Context context)
{
if (location != null)
{
Geocoder geocoder = new Geocoder(context, Locale.ENGLISH);
try
{
List<Address> addresses = geocoder.getFromLocation(latitude, longitude, 1);
return addresses;
}
catch (IOException e)
{
//e.printStackTrace();
Log.e("Error : Geocoder", "Impossible to connect to Geocoder", e);
}
}
return null;
}
示例9: getLocationName
import android.location.Geocoder; //导入方法依赖的package包/类
@ProtoMethod(description = "Get the location name of a given latitude and longitude", example = "")
@ProtoMethodParam(params = {"latitude", "longitude"})
public String getLocationName(double lat, double lon) {
String gpsLocation = "";
Geocoder gcd = new Geocoder(getContext(), Locale.getDefault());
List<Address> addresses;
try {
addresses = gcd.getFromLocation(lat, lon, 1);
gpsLocation = addresses.get(0).getLocality();
} catch (IOException e) {
e.printStackTrace();
}
return gpsLocation;
}
示例10: getCompleteAddressString
import android.location.Geocoder; //导入方法依赖的package包/类
@SuppressLint("LongLogTag")
private String getCompleteAddressString(double LATITUDE, double LONGITUDE) {
String strAdd = "";
Geocoder geocoder = new Geocoder(context, Locale.getDefault());
try {
List<Address> addresses = geocoder.getFromLocation(LATITUDE, LONGITUDE, 1);
if (addresses != null) {
Address returnedAddress = addresses.get(0);
StringBuilder strReturnedAddress = new StringBuilder("");
for (int i = 0; i < returnedAddress.getMaxAddressLineIndex(); i++) {
strReturnedAddress.append(returnedAddress.getAddressLine(i)).append("\n");
}
strAdd = strReturnedAddress.toString();
Log.w("My Current loction address", "" + strReturnedAddress.toString());
} else {
Log.w("My Current loction address", "No Address returned!");
}
} catch (Exception e) {
e.printStackTrace();
Log.w("My Current loction address", "Canont get Address!");
}
return strAdd;
}
示例11: getLocalityName
import android.location.Geocoder; //导入方法依赖的package包/类
@Nullable
public static String getLocalityName(Context context, LatLng latLng) {
Geocoder gcd = new Geocoder(context, Locale.getDefault());
try {
List<Address> addresses = gcd.getFromLocation(latLng.latitude, latLng.longitude, 1);
if (addresses.size() > 0) {
Address address = addresses.get(0);
String name = address.getCountryName();
if (address.getLocality() != null)
name = address.getLocality() + ", " + name;
return name;
}
} catch (IOException ex) {
Log.d(TAG, Log.getStackTraceString(ex));
}
return null;
}
示例12: getAddress
import android.location.Geocoder; //导入方法依赖的package包/类
/**
* get address info
*/
private Address getAddress(double latitude, double longitude) {
if(WXEnvironment.isApkDebugable()) {
WXLogUtils.d(TAG, "into--[getAddress] latitude:" + latitude + " longitude:" + longitude);
}
try {
if (mWXSDKInstance == null || mWXSDKInstance.isDestroy()) {
return null;
}
Geocoder gc = new Geocoder(mWXSDKInstance.getContext());
List<Address> list = gc.getFromLocation(latitude, longitude, 1);
if (list != null && list.size() > 0) {
return list.get(0);
}
} catch (Exception e) {
WXLogUtils.e(TAG, e);
}
return null;
}
示例13: setCurrentLocation
import android.location.Geocoder; //导入方法依赖的package包/类
/**
* Set current location from map
* TODO: Faire mieux la difference entre une location exacte et une
*
* @param location the location returned from the map picker
*/
public void setCurrentLocation(Intent data) {
final Place place = PlacePicker.getPlace(getActivity(), data);
Geocoder geocoder = new Geocoder(getActivity());
try {
List<Address> addresses = geocoder.getFromLocation(place.getLatLng().latitude, place.getLatLng().longitude, 1);
elephant.currentLoc.cityName = addresses.get(0).getAddressLine(0);
if (!addresses.get(0).getAddressLine(0).equals(addresses.get(0).getSubAdminArea())) {
elephant.currentLoc.districtName = addresses.get(0).getSubAdminArea();
}
elephant.currentLoc.provinceName = addresses.get(0).getAdminArea();
} catch (IOException e) {
e.printStackTrace();
}
currentLocation.setText(elephant.currentLoc.format());
}
示例14: getAddress
import android.location.Geocoder; //导入方法依赖的package包/类
/**
* Get address string from a geo point
*
* @return the address as a string.
*/
// see code attribution
public static String getAddress(Context context, double latitude, double longitude) {
String pointAddress;
try {
Geocoder geocoder = new Geocoder(context);
List<Address> addresses = geocoder.getFromLocation(latitude, longitude, 1);
StringBuilder sb = new StringBuilder();
if(addresses.size() > 0) {
Address address = addresses.get(0);
int n = address.getMaxAddressLineIndex();
for(int i = 0; i <= n; i++) {
if(i != 0) {
sb.append("\n");
}
sb.append(address.getAddressLine(i));
}
pointAddress = new String(sb);
} else {
pointAddress = "";
}
} catch (Exception e) {
pointAddress = "";
}
return pointAddress;
}
示例15: getGeocoderAddress
import android.location.Geocoder; //导入方法依赖的package包/类
/**
* Get list of address by latitude and longitude
* @return null or List<Address>
*/
public List<Address> getGeocoderAddress(Context context) {
if (location != null) {
Geocoder geocoder = new Geocoder(context, Locale.ENGLISH);
try {
/**
* Geocoder.getFromLocation - Returns an array of Addresses
* that are known to describe the area immediately surrounding the given latitude and longitude.
*/
List<Address> addresses = geocoder.getFromLocation(latitude, longitude, this.geocoderMaxResults);
return addresses;
} catch (IOException e) {
//e.printStackTrace();
L.m("Impossible to connect to Geocoder");
}
}
return null;
}