如何解决给定纬度和经度,获取位置名称
| 我正在开发一个应用程序,可以在我的android设备中获取经度和纬度并将其发布到Web服务器。 并在网络应用程序中借助Google地图显示位置详细信息。 在这里,我收集了大量的经纬度值,这些值在我的jsp中循环并使用信息窗口创建多个标记。 现在的问题是,我需要在Google地图的信息窗口中显示特定纬度和经度的位置名称。 任何人都可以通过Google Maps脚本帮助我,或者如何从Android手机本身的经纬度值中获取位置名称,以便将其发布到Web服务器。解决方法
在这里,我仅通过此函数传递一个纬度和经度,然后您就获得了与此纬度和经度有关的所有信息。
public void getAddress(double lat,double lng) {
Geocoder geocoder = new Geocoder(HomeActivity.mContext,Locale.getDefault());
try {
List<Address> addresses = geocoder.getFromLocation(lat,lng,1);
Address obj = addresses.get(0);
String add = obj.getAddressLine(0);
add = add + \"\\n\" + obj.getCountryName();
add = add + \"\\n\" + obj.getCountryCode();
add = add + \"\\n\" + obj.getAdminArea();
add = add + \"\\n\" + obj.getPostalCode();
add = add + \"\\n\" + obj.getSubAdminArea();
add = add + \"\\n\" + obj.getLocality();
add = add + \"\\n\" + obj.getSubThoroughfare();
Log.v(\"IGA\",\"Address\" + add);
// Toast.makeText(this,\"Address=>\" + add,// Toast.LENGTH_SHORT).show();
// TennisAppActivity.showDialog(add);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Toast.makeText(this,e.getMessage(),Toast.LENGTH_SHORT).show();
}
}
我希望你能回答。
, 对于几个月前发布的我自己的问题,我有一个非常简单的答案....请检查一下...它对我有用..
Geocoder myLocation = new Geocoder(yourContext,Locale.getDefault());
List<Address> myList = myLocation.getFromLocation(Double.parseDouble(latitude),Double.parseDouble(longitude),1);
Address address = (Address) myList.get(0);
String addressStr = \"\";
addressStr += address.getAddressLine(0) + \",\";
addressStr += address.getAddressLine(1) + \",\";
addressStr += address.getAddressLine(2);
, 这是代码...
StringBuilder _homeAddress = null;
try{
_homeAddress = new StringBuilder();
Address address = null;
List<Address> addresses = _coder.getFromLocation(_lat,_lon,1);
for(int index=0; index<addresses.size(); ++index)
{
address = addresses.get(index);
_homeAddress.append(\"Name: \" + address.getLocality() + \"\\n\");
_homeAddress.append(\"Sub-Admin Ares: \" + address.getSubAdminArea() + \"\\n\");
_homeAddress.append(\"Admin Area: \" + address.getAdminArea() + \"\\n\");
_homeAddress.append(\"Country: \" + address.getCountryName() + \"\\n\");
_homeAddress.append(\"Country Code: \" + address.getCountryCode() + \"\\n\");
_homeAddress.append(\"Latitude: \" + address.getLatitude() + \"\\n\");
_homeAddress.append(\"Longitude: \" + address.getLongitude() + \"\\n\\n\");
}
}
catch(Exception e){
}
, 使用android.location.geocoder.getFromLocation(double latitude,double longitude,int maxResults)
它会给你一个地址列表。
, 它为我工作:
public void getAddress(double lat,double lng) {
Geocoder geocoder = new Geocoder(DistaceCalculating.this,Locale.getDefault());
try {
List<Address> addresses = geocoder.getFromLocation(lat,1);
Address obj = addresses.get(0);
String add = obj.getAddressLine(0);
String currentAddress = obj.getSubAdminArea() + \",\"
+ obj.getAdminArea();
double latitude = obj.getLatitude();
double longitude = obj.getLongitude();
String currentCity= obj.getSubAdminArea();
String currentState= obj.getAdminArea();
add = add + \"\\n\" + obj.getCountryName();
add = add + \"\\n\" + obj.getCountryCode();
add = add + \"\\n\" + obj.getAdminArea();
add = add + \"\\n\" + obj.getPostalCode();
add = add + \"\\n\" + obj.getSubAdminArea();
add = add + \"\\n\" + obj.getLocality();
add = add + \"\\n\" + obj.getSubThoroughfare();
System.out.println(\"obj.getCountryName()\"+obj.getCountryName());
System.out.println(\"obj.getCountryCode()\"+obj.getCountryCode());
System.out.println(\"obj.getAdminArea()\"+obj.getAdminArea());
System.out.println(\"obj.getPostalCode()\"+obj.getPostalCode());
System.out.println(\"obj.getSubAdminArea()\"+obj.getSubAdminArea());
System.out.println(\"obj.getLocality()\"+obj.getLocality());
System.out.println(\"obj.getSubThoroughfare()\"+obj.getSubThoroughfare());
Log.v(\"IGA\",\"Address\" + add);
// Toast.makeText(this,// Toast.LENGTH_SHORT).show();
// TennisAppActivity.showDialog(add);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Toast.makeText(this,Toast.LENGTH_SHORT).show();
}
}
, 干得好!
private String getAddress() {
GPSTracker gps = new GPSTracker(ProductList.this);
Geocoder geocoder = new Geocoder(ProductList.this,Locale.getDefault());
String address=\"\";
try {
List<Address> addresses = geocoder.getFromLocation(gps.getLatitude(),gps.getLongitude(),1);
Address obj = addresses.get(0);
String add = obj.getAddressLine(0);
//optional
/* add = add + \"\\n\" + obj.getCountryName();
add = add + \"\\n\" + obj.getCountryCode();
add = add + \"\\n\" + obj.getAdminArea();
add = add + \"\\n\" + obj.getPostalCode();
add = add + \"\\n\" + obj.getSubAdminArea();
add = add + \"\\n\" + obj.getLocality();
add = add + \"\\n\" + obj.getSubThoroughfare();*/
Log.e(\"Location\",\"Address\" + add);
address=add;
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Toast.makeText(this,Toast.LENGTH_SHORT).show();
}
return address;
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。