LWUIT引路蜂地图开发示例:地址反编码

jerry 2015年11月26日 收藏

地址反编码是通过经纬度查询对应的地名,下面示例是查询经纬度为118.777802, 32.061699对应的地名,结果为”中国江苏省南京市鼓楼区渊声巷41号”。

  1. package com.pstreets.gisengine.demo.lwuit;
  2.  
  3. //--------------------------------- IMPORTS ------------------------------------
  4.  
  5. import com.mapdigit.gis.MapPoint;
  6.  
  7. import com.mapdigit.gis.geometry.GeoLatLng;
  8. import com.mapdigit.gis.raster.MapType;
  9. import com.mapdigit.gis.service.IReverseGeocodingListener;
  10. import com.pstreets.gisengine.demo.MapDemoLWUIT;
  11. import com.sun.lwuit.Command;
  12. import com.sun.lwuit.events.ActionEvent;
  13.  
  14. public class MapReverseGeocodingLWUIT extends MapDemoLWUIT
  15.         implements IReverseGeocodingListener{
  16.  
  17.     private Command mapFindAddressCommand;
  18.  
  19.     public void startApp() {
  20.         init();
  21.         canvas.setTitle("Map Reverse Geocoding");
  22.  
  23.         mapFindAddressCommand=new Command("Find Address"){
  24.             public void actionPerformed(ActionEvent evt) {
  25.                  map.getReverseLocations("32.061699,118.777802");
  26.  
  27.             }
  28.         };
  29.         canvas.addCommand(mapFindAddressCommand);
  30.         GeoLatLng center =  new GeoLatLng(32.0616667, 118.7777778);
  31.         map.setCenter(center, 13, MapType.MICROSOFTCHINA);
  32.          map.setReverseGeocodingListener(this);
  33.  
  34.         canvas.show();
  35.     }
  36.  
  37.     public void done(String arg0, MapPoint[] result) {
  38.         if (result != null) {
  39.             map.panTo(result[0].getPoint());
  40.         }
  41.     }
  42. }

注意使用字符串经纬度格式时,纬度在前,经度在后,如果反了,则返回的地名或能为空或都跑到外国去了。结果也是一个数组,一般到第一个结果,后面结果是更大的区域或是距离相对较远的地名。