本文整理汇总了Java中org.osmdroid.bonuspack.location.GeocoderNominatim类的典型用法代码示例。如果您正苦于以下问题:Java GeocoderNominatim类的具体用法?Java GeocoderNominatim怎么用?Java GeocoderNominatim使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
GeocoderNominatim类属于org.osmdroid.bonuspack.location包,在下文中一共展示了GeocoderNominatim类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doInBackground
import org.osmdroid.bonuspack.location.GeocoderNominatim; //导入依赖的package包/类
@Override
protected Void doInBackground(Void... voids) {
GeocoderNominatim nominatim = new GeocoderNominatim(context.getResources().getString(R.string.user_agent));
try {
List<Address> addresses = nominatim.getFromLocation(latitude, longitude, 1);//only get one location
if (addresses != null && addresses.size() > 0) {
reverseGeocodedAddress = addresses.get(0);
Bundle bundle = addresses.get(0).getExtras();
String osm_type = bundle.getString("osm_type");
AppLog.log(addresses.get(0));
//only osm nodes are filtered though
// if (osm_type.equals("node")) {
double nodeLat = reverseGeocodedAddress.getLatitude();
double nodeLon = reverseGeocodedAddress.getLongitude();
//The geocoding is considered as valid if the node location
//is under the distance 4 meters form the provided location (user click location on map)
AppLog.log(distance(latitude, nodeLat, longitude, nodeLon, 0, 0));
if (distance(latitude, nodeLat, longitude, nodeLon, 0, 0) < 4) {
long osm_id = bundle.getLong("osm_id");
getNode(connection, osm_id);
}
// } else {
// //Do noting
// }
}
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
示例2: doInBackground
import org.osmdroid.bonuspack.location.GeocoderNominatim; //导入依赖的package包/类
@Override
protected List<Address> doInBackground(String... addresses) {
List<Address> addressList = null;
GeocoderNominatim geoNom = new GeocoderNominatim("");
try {
// we are only getting a maximum of 50 matching addresses
addressList = geoNom.getFromLocationName(addresses[0], 50);
} catch (IOException e) {
e.printStackTrace();
}
return addressList;
}
示例3: getAddress
import org.osmdroid.bonuspack.location.GeocoderNominatim; //导入依赖的package包/类
/**
* Reverse Geocoding
*/
public String getAddress(GeoPoint p) {
GeocoderNominatim geocoder = new GeocoderNominatim(this);
String theAddress;
try {
double dLatitude = p.getLatitudeE6() * 1E-6;
double dLongitude = p.getLongitudeE6() * 1E-6;
List<Address> addresses = geocoder.getFromLocation(dLatitude,
dLongitude, 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(", ");
sb.append(address.getAddressLine(i));
}
theAddress = new String(sb.toString());
} else {
theAddress = null;
}
} catch (IOException e) {
theAddress = null;
}
if (theAddress != null) {
return theAddress;
} else {
return "";
}
}