Baidu Maps - Geocoding and Anti-Geocoding
ONE Goal,ONE Passion !
Geocoding:
Geocoding - is to resolve our familiar addresses into latitude and longitude. For example:
address | LatLng(coordinates) |
---|---|
Zhengzhou | 34.7568711, 113.663221 |
Ok, the code is very simple
//新建编码查询对象
GeoCoder geocode = GeoCoder.newInstance();
//新建查询对象要查询的条件
GeoCodeOption GeoOption = new GeoCodeOption().city("郑州").address("郑州东站");
//发起地理编码请求
geocode.geocode(GeoOption);
//设置查询结果监听者
geocode.setOnGetGeoCodeResultListener(new OnGetGeoCoderResultListener() {
/**
* 反地理编码查询结果回调函数
* @param result 反地理编码查询结果
*/
@Override
public void onGetReverseGeoCodeResult(ReverseGeoCodeResult result) {
}
}
/**
* 地理编码查询结果回调函数
* @param result 地理编码查询结果
*/
@Override
public void onGetGeoCodeResult(GeoCodeResult result) {
System.out.println("地理编码查询结果" + result.getLocation());
}
});
Anti-geocoding:
Anti-geocoding - is to parse latitude and longitude coordinates into geographic locations that we can understand. For example:
LatLng(coordinates) | address |
---|---|
34.7568711, 113.663221 | Zhengzhou |
//新建编码查询对象
geocode = GeoCoder.newInstance();
//新建查询对象要查询的条件
ReverseGeoCodeOption options = new ReverseGeoCodeOption().location(ll);
// 发起反地理编码请求
geocode.reverseGeoCode(options);
//设置查询结果监听者
geocode.setOnGetGeoCodeResultListener(new OnGetGeoCoderResultListener() {
/**
* 反地理编码查询结果回调函数
* @param result 反地理编码查询结果
*/
@Override
public void onGetReverseGeoCodeResult(ReverseGeoCodeResult result) {
if (result == null || result.error != SearchResult.ERRORNO.NO_ERROR) {
return;
}
if (result != null && result.error == SearchResult.ERRORNO.NO_ERROR) {
//得到位置
address = result.getAddress();
System.out.println("得到位置" + address);
}
}
/**
* 地理编码查询结果回调函数
* @param result 地理编码查询结果
*/
@Override
public void onGetGeoCodeResult(GeoCodeResult result) {
}
});
The address encoding and anti-encoding of Baidu Maps have been completed, which is really simple!