Java ME引路蜂地图开发示例:本地查询

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

本地查询可以查询指定区域内诸如宾馆,邮局等用户感兴趣的地方。其使用方法和地址查询非常类似。
下面示例查询32.0616667, 118.7777778为中心点一定区域内宾馆的信息。

  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.IGeocodingListener;
  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 MapLocalSearchMIDP extends MapDemoMIDP implements CommandListener,
  37.         IGeocodingListener {
  38.  
  39.     private Command mapFindAddressCommand = new Command("Find Address",
  40.             Command.OK, 1);
  41.  
  42.     public void startApp() {
  43.  
  44.         init();
  45.         canvas.addCommand(mapFindAddressCommand);
  46.         map.setGeocodingListener(this);
  47.         canvas.setCommandListener(this);
  48.         GeoLatLng center = new GeoLatLng(32.0616667, 118.7777778);
  49.         map.setCenter(center, 13, MapType.MICROSOFTCHINA);
  50.         Display.getDisplay(this).setCurrent(canvas);
  51.     }
  52.  
  53.     public void commandAction(Command c, Displayable d) {
  54.         if (c == mapFindAddressCommand) {
  55.             String name = "宾馆";
  56.                 GeoLatLng screenCenter = map.getScreenCenter();
  57.                 map.getLocations(name, 0, screenCenter,
  58.                         map.getScreenBounds(screenCenter));
  59.         }
  60.     }
  61.  
  62.     public void done(String query, MapPoint[] result) {
  63.         if (result != null) {
  64.             map.panTo(result[0].getPoint());
  65.             for (int i = 0; i < result.length; i++) {
  66.                 System.out.println(result[i].objectNote);
  67.             }
  68.         }
  69.     }
  70. }

本地查询方法
public void getLocations(String address,int start,GeoLatLng center,GeoBounds bound, IGeocodingListener listener);
指定中心点和查询区域。本地查询可以多次返回结果,start为查询结果起始顺序,每次返回结果在SearchOptions 中定义,缺省每次返回4个。
上述结果返回内容为,具体结果可能不同。
?晶丽酒店025-83310818 025-83310818212223 025-86636636 ?
?城市名人酒店025-83123333 025-83123888 ?
?南京玄武饭店 025-83358888 ?
?Sofitel Galaxy Nanjing ? 南京索菲特银河大酒店025-83718888 ?