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

jerry 地图开发 2015年11月26日 收藏

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

  1. //------------------------------------------------------------------------------
  2. //                         COPYRIGHT 2011 GUIDEBEE
  3. //                           ALL RIGHTS RESERVED.
  4. //                     GUIDEBEE CONFIDENTIAL PROPRIETARY
  5. ///////////////////////////////////// REVISIONS ////////////////////////////////
  6. // Date       Name                 Tracking #         Description
  7. // ---------  -------------------  ----------         --------------------------
  8. // 28JAN2011  James Shen                              Initial Creation
  9. ////////////////////////////////////////////////////////////////////////////////
  10. //--------------------------------- PACKAGE ------------------------------------
  11. package com.pstreets.gisengine.demo.midp;
  12.  
  13. //--------------------------------- IMPORTS ------------------------------------
  14. import com.mapdigit.gis.MapPoint;
  15. import com.mapdigit.gis.geometry.GeoLatLng;
  16. import com.mapdigit.gis.raster.MapType;
  17. import com.mapdigit.gis.service.IReverseGeocodingListener;
  18. import com.pstreets.gisengine.demo.MapDemoMIDP;
  19. import javax.microedition.lcdui.Command;
  20. import javax.microedition.lcdui.CommandListener;
  21. import javax.microedition.lcdui.Display;
  22. import javax.microedition.lcdui.Displayable;
  23.  
  24. //[------------------------------ MAIN CLASS ----------------------------------]
  25. //--------------------------------- REVISIONS ----------------------------------
  26. // Date       Name                 Tracking #         Description
  27. // --------   -------------------  -------------      --------------------------
  28. // 28JAN2011  James Shen                              Initial Creation
  29. ////////////////////////////////////////////////////////////////////////////////
  30. /**
  31.  *  map pan demo for Guidebee Map API on MIDP platform.
  32.  * <hr><b>&copy; Copyright 2011 Guidebee, Inc. All Rights Reserved.</b>
  33.  * @version     1.00, 28/01/11
  34.  * @author      Guidebee Pty Ltd.
  35.  */
  36. public class MapReverseGeocodingMIDP extends MapDemoMIDP implements
  37.         CommandListener,
  38.         IReverseGeocodingListener {
  39.  
  40.     private Command mapFindAddressCommand = new Command("Find Address",
  41.             Command.OK, 1);
  42.  
  43.     public void startApp() {
  44.  
  45.         init();
  46.         canvas.addCommand(mapFindAddressCommand);
  47.         map.setReverseGeocodingListener(this);
  48.         canvas.setCommandListener(this);
  49.         GeoLatLng center = new GeoLatLng(32.0616667, 118.7777778);
  50.         map.setCenter(center, 13, MapType.MICROSOFTCHINA);
  51.         Display.getDisplay(this).setCurrent(canvas);
  52.     }
  53.  
  54.     public void commandAction(Command c, Displayable d) {
  55.         if (c == mapFindAddressCommand) {
  56.             map.getReverseLocations("32.061699,118.777802");
  57.         }
  58.     }
  59.  
  60.     public void done(String arg0, MapPoint[] result) {
  61.         if (result != null) {
  62.             map.panTo(result[0].getPoint());
  63.         }
  64.     }
  65. }

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