public GeoPoint getGeoPointBystr(String str) {//GeoPoint来自谷歌
GeoPoint gpGeoPoint = null;
if (str!=null) {
Geocoder gc = new Geocoder(Demo2Activity.this,Locale.CHINA);
List<Address> addressList = null;
try {
addressList = gc.getFromLocationName(str, 1);
Log.i("tag","addressList=="+addressList.size());
if (!addressList.isEmpty()) {
Address address_temp = addressList.get(0);
//计算经纬度
double Latitude=address_temp.getLatitude()*1E6;
double Longitude=address_temp.getLongitude()*1E6;
System.out.println("经度:"+Latitude);
System.out.println("纬度:"+Longitude);
//生产GeoPoint
gpGeoPoint = new GeoPoint((int)Longitude, (int)Latitude);
}
else{
Log.i("tag","Demo2Activity:else");
}
} catch (IOException e) {
e.printStackTrace();
}
}
return gpGeoPoint;
}
GeoPoint gpGeoPoint = null;
if (str!=null) {
Geocoder gc = new Geocoder(Demo2Activity.this,Locale.CHINA);
List<Address> addressList = null;
try {
addressList = gc.getFromLocationName(str, 1);
Log.i("tag","addressList=="+addressList.size());
if (!addressList.isEmpty()) {
Address address_temp = addressList.get(0);
//计算经纬度
double Latitude=address_temp.getLatitude()*1E6;
double Longitude=address_temp.getLongitude()*1E6;
System.out.println("经度:"+Latitude);
System.out.println("纬度:"+Longitude);
//生产GeoPoint
gpGeoPoint = new GeoPoint((int)Longitude, (int)Latitude);
}
else{
Log.i("tag","Demo2Activity:else");
}
} catch (IOException e) {
e.printStackTrace();
}
}
return gpGeoPoint;
}
本文介绍了一种通过字符串地址获取GeoPoint对象的方法。利用Geocoder类从指定位置名称获取地理位置信息,并转换为GeoPoint坐标。文章详细展示了如何使用Geocoder获取地址列表,计算经纬度并创建GeoPoint。
1819

被折叠的 条评论
为什么被折叠?



