Facebook Twitter LinkedIn E-mail
magnify
Home Archive for category "Blackberry"

Blackberry引路蜂地图开发包Ver2.1下载

Blackberry 地图开发包下载.

JavaDoc 下载
Blackberry引路蜂地图开发库 下载
Blackberry引路蜂地图开发示例 下载
引路蜂地图开发指南 下载
  1. Blackberry引路蜂地图开发示例:概述
  2. Blackberry引路蜂地图开发示例:第一个地图应用
  3. Blackberry引路蜂地图开发示例:设置地图类型
  4. Blackberry引路蜂地图开发示例:地图平移
  5. Blackberry引路蜂地图开发示例:放大、缩小
  6. Blackberry引路蜂地图开发示例:地址查询
  7. Blackberry引路蜂地图开发示例:路径查询
  8. Blackberry引路蜂地图开发示例:本地查询
  9. Blackberry引路蜂地图开发示例:IP地址查询
  10. Blackberry引路蜂地图开发示例:地址反编码
  11. Blackberry引路蜂地图开发示例:选择地图服务
  12. Blackberry引路蜂地图开发示例:叠加自定义图层
  13. 离线地图下载方法解析
  14. 自定义地图示例:天地图(一)
  15. 自定义地图示例:天地图(二)
 

离线地图下载方法解析

在使用Google Map, Microsoft Map 等在线地图时,常常想知道这些地图在服务器上是如何存放的,目前大部分地图服务器都是将地图以图片存储以提高响应速度。 一般大小为256X256个像素。
如果知道每个图片的URL,自己写个地图下载软件并不困难。从而做成离线地图。
下面程序片段给出了常用地图服务器上地图图片存取的URL计算方法。

using System.Collections.Generic;
using System.Text;
namespace MapTileURL
{
    class Program
    {
        private static Dictionary<string, string> MapTypeURLs = new Dictionary<string, string>
        {
            { "GoogleSatURL", "<a href="http://khm{GOOG_DIGIT}.google.com/kh/v=58&x={X}&y={Y}&z={ZOOM}&s={GALILEO">http://khm{GOOG_DIGIT}.google.com/kh/v=58&x={X}&y={Y}&z={ZOOM}&s={GALILEO</a>}" },
            { "GoogleMapURL", "<a href="http://mt{GOOG_DIGIT}.google.com/vt/lyrs=m@121&hl=en&x={X}&y={Y}&z={ZOOM}&s={GALILEO">http://mt{GOOG_DIGIT}.google.com/vt/lyrs=m@121&hl=en&x={X}&y={Y}&z={ZOOM}&s={GALILEO</a>}" },
            { "GoogleHybURL", "<a href="http://mt{GOOG_DIGIT}.google.com/vt/lyrs=h@121&hl=en&x={X}&y={Y}&z={ZOOM}&s={GALILEO">http://mt{GOOG_DIGIT}.google.com/vt/lyrs=h@121&hl=en&x={X}&y={Y}&z={ZOOM}&s={GALILEO</a>}" },
            { "GoogleTerURL", "<a href="http://mt{GOOG_DIGIT}.google.com/vt/lyrs=t@108,r@121&hl=en&x={X}&y={Y}&z={ZOOM}&s={GALILEO">http://mt{GOOG_DIGIT}.google.com/vt/lyrs=t@108,r@121&hl=en&x={X}&y={Y}&z={ZOOM}&s={GALILEO</a>}" },
            { "GoogleChinaURL", "<a href="http://mt{GOOG_DIGIT}.google.cn/vt/lyrs=m@121&hl=en&gl=cn&x={X}&y={Y}&z={ZOOM}&s={GALILEO">http://mt{GOOG_DIGIT}.google.cn/vt/lyrs=m@121&hl=en&gl=cn&x={X}&y={Y}&z={ZOOM}&s={GALILEO</a>}" },
            { "YahooMapURL", "<a href="http://maps{Y_DIGIT}.yimg.com/hx/tl?v=4.3&.intl=en&x={X}&y={YAHOO_Y}&z={YAHOO_ZOOM}&r=1">http://maps{Y_DIGIT}.yimg.com/hx/tl?v=4.3&.intl=en&x={X}&y={YAHOO_Y}&z={YAHOO_ZOOM}&r=1</a>" },
            { "YahooSatURL", "<a href="http://maps{Y_DIGIT}.yimg.com/ae/ximg?v=1.9&t=a&s=256&.intl=en&x={X}&y={YAHOO_Y}&z={YAHOO_ZOOM}&r=1">http://maps{Y_DIGIT}.yimg.com/ae/ximg?v=1.9&t=a&s=256&.intl=en&x={X}&y={YAHOO_Y}&z={YAHOO_ZOOM}&r=1</a>" },
            { "YahooInMapURL", "<a href="http://maps.yimg.com/hw/tile?locale=en&imgtype=png&yimgv=1.2&v=4.1&x={X}&y={YAHOO_Y}&z={YAHOO_ZOOM_2">http://maps.yimg.com/hw/tile?locale=en&imgtype=png&yimgv=1.2&v=4.1&x={X}&y={YAHOO_Y}&z={YAHOO_ZOOM_2</a>}" },
            { "YahooInHybURL", "<a href="http://maps.yimg.com/hw/tile?imgtype=png&yimgv=0.95&t=h&x={X}&y={YAHOO_Y}&z={YAHOO_ZOOM_2">http://maps.yimg.com/hw/tile?imgtype=png&yimgv=0.95&t=h&x={X}&y={YAHOO_Y}&z={YAHOO_ZOOM_2</a>}" },
            { "YahooHybURL", "<a href="http://maps{Y_DIGIT}.yimg.com/hx/tl?v=4.3&t=h&.intl=en&x={X}&y={YAHOO_Y}&z={YAHOO_ZOOM}&r=1">http://maps{Y_DIGIT}.yimg.com/hx/tl?v=4.3&t=h&.intl=en&x={X}&y={YAHOO_Y}&z={YAHOO_ZOOM}&r=1</a>" },
            { "MicrosoftBrMapURL", "<a href="http://imakm{MS_DIGITBR}.maplink3.com.br/maps.ashx?v={QUAD}|t&call=2.2.4">http://imakm{MS_DIGITBR}.maplink3.com.br/maps.ashx?v={QUAD}|t&call=2.2.4</a>" },
            { "MicrosoftHybURL", "<a href="http://ecn.t{MS_DIGIT}.tiles.virtualearth.net/tiles/h{QUAD}.png?g=441&mkt=en-us&n=z">http://ecn.t{MS_DIGIT}.tiles.virtualearth.net/tiles/h{QUAD}.png?g=441&mkt=en-us&n=z</a>" },
            { "MicrosoftSatURL", "<a href="http://ecn.t{MS_DIGIT}.tiles.virtualearth.net/tiles/a{QUAD}.png?g=441&mkt=en-us&n=z">http://ecn.t{MS_DIGIT}.tiles.virtualearth.net/tiles/a{QUAD}.png?g=441&mkt=en-us&n=z</a>" },
            { "MicrosoftMapURL", "<a href="http://ecn.t{MS_DIGIT}.tiles.virtualearth.net/tiles/r{QUAD}.png?g=441&mkt=en-us&n=z">http://ecn.t{MS_DIGIT}.tiles.virtualearth.net/tiles/r{QUAD}.png?g=441&mkt=en-us&n=z</a>" },
            { "MicrosoftTerURL", "<a href="http://ecn.t{MS_DIGIT}.tiles.virtualearth.net/tiles/r{QUAD}.png?g=441&mkt=en-us&shading=hill&n=z">http://ecn.t{MS_DIGIT}.tiles.virtualearth.net/tiles/r{QUAD}.png?g=441&mkt=en-us&shading=hill&n=z</a>" },
            { "OpenStreetMapURL", "<a href="http://tile.openstreetmap.org/{ZOOM}/{X}/{Y}.png">http://tile.openstreetmap.org/{ZOOM}/{X}/{Y}.png</a>" },
            { "OSMARenderURL", "<a href="http://tah.openstreetmap.org/Tiles/tile/{ZOOM}/{X}/{Y}.png">http://tah.openstreetmap.org/Tiles/tile/{ZOOM}/{X}/{Y}.png</a>" },
            { "OpenAerialMapURL", "<a href="http://tile.openaerialmap.org/tiles/?v=mgm&layer=openaerialmap-900913&x={X}&y={Y}&zoom={OAM_ZOOM">http://tile.openaerialmap.org/tiles/?v=mgm&layer=openaerialmap-900913&x={X}&y={Y}&zoom={OAM_ZOOM</a>}" },
            { "OpenCycleMapURL", "<a href="http://andy.sandbox.cloudmade.com/tiles/cycle/{ZOOM}/{X}/{Y}.png">http://andy.sandbox.cloudmade.com/tiles/cycle/{ZOOM}/{X}/{Y}.png</a>" }
        };
        readonly static char[] Lookup = new[] { 'q', 't', 'r', 's' };
        public static string GetQuadtreeFromXYZoom(int x, int y, int zoom)
        {
            var quad = new StringBuilder();
            for (int i = 0; i < zoom; i++)
            {
                int rx = x % 2;
                int ry = y % 2;
                x /= 2;
                y /= 2;
                quad.Insert(0, Lookup[rx * 2 + ry]);
            }
            quad.Insert(0, 't');
            return quad.ToString();
        }
        public static string BuildUrl(string tileType, int x,int y,int zoom)
        {
    
            string url = "";
            // Edited by Shustrik - compacted the switch statement
            switch (tileType)
            {
                case "GoogleSat":
                case "GoogleSatH":
                    url = MapTypeURLs["GoogleSatURL"];
                    break;
                case "GoogleMap":
                    url = MapTypeURLs["GoogleMapURL"];
                    break;
                case "GoogleHyb":
                    url = MapTypeURLs["GoogleHybURL"];
                    break;
                case "GoogleTer":
                    url = MapTypeURLs["GoogleTerURL"];
                    break;
                case "GoogleChina":
                    url = MapTypeURLs["GoogleChinaURL"];
                    break;
                case "MicrosoftMap":
                    url = MapTypeURLs["MicrosoftMapURL"];
                    break;
                case "MicrosoftSat":
                    url = MapTypeURLs["MicrosoftSatURL"];
                    break;
                case "MicrosoftHyb":
                    url = MapTypeURLs["MicrosoftHybURL"];
                    break;
                case "MicrosoftTer":
                    url = MapTypeURLs["MicrosoftTerURL"];
                    break;
                case "MicrosoftBrMap":
                    if (zoom <= 10)
                        url =  MapTypeURLs["MicrosoftMapURL"];
                    else
                        url = MapTypeURLs["MicrosoftBrMapURL"];
                    break;
                case "YahooMap":
                    url = MapTypeURLs["YahooMapURL"];
                    break;
                case "YahooSat":
                case "YahooSatH":
                case "YahooSatH2":
                    url = MapTypeURLs["YahooSatURL"];
                    break;
                case "YahooHyb":
                    url = MapTypeURLs["YahooHybURL"];
                    break;
                case "YahooInMap":
                    url = MapTypeURLs["YahooInMapURL"];
                    break;
                case "YahooInHyb":
                    url = MapTypeURLs["YahooInHybURL"];
                    break;
                case "OpenStreetMap":
                    url = MapTypeURLs["OpenStreetMapURL"];
                    break;
                case "OSMARender":
                    url = MapTypeURLs["OSMARenderURL"];
                    break;
                case "OpenAerialMap":
                    url = MapTypeURLs["OpenAerialMapURL"];
                    break;
                case "OpenCycleMap":
                    url = MapTypeURLs["OpenCycleMapURL"];
                    break;
            }
          
            // Edited by Shustrik - added variables for configuration settings other than Google
            string quadcode = "";
            for (int i = (int)zoom - 1; i >= 0; i--)
                quadcode = quadcode + (((((y >> i) & 1) << 1) + ((x >> i) & 1)));
            url = url.Replace("{X}", x.ToString());
            url = url.Replace("{Y}", y.ToString());
            url = url.Replace("{Z}", ((int)zoom).ToString());
            url = url.Replace("{ZOOM}", ((int)zoom).ToString());
            url = url.Replace("{QUAD}", quadcode);
            url = url.Replace("{YAHOO_Y}", (((1 << ((int)zoom)) >> 1) - 1 - y).ToString());
            url = url.Replace("{YAHOO_ZOOM}", ((int)zoom + 1).ToString());
            url = url.Replace("{YAHOO_ZOOM_2}", (17 - (int)zoom + 1).ToString());
            url = url.Replace("{OAM_ZOOM}", (17 - (int)zoom).ToString());
            url = url.Replace("{GOOG_DIGIT}", ((x + y) & 3).ToString());
            url = url.Replace("{GOOG_QUAD}", GetQuadtreeFromXYZoom(x, y, zoom));
            url = url.Replace("{MS_DIGITBR}", ((((y & 1) << 1) + (x & 1)) + 1).ToString());
            url = url.Replace("{MS_DIGIT}", ((((y & 3) << 1) + (x & 1))).ToString());
            url = url.Replace("{Y_DIGIT}", ((x + y + zoom) % 3 +1).ToString());
            url = url.Replace("{GALILEO}", "Galileo".Substring(0, ((3 * x + y) & 7)));
            // support old style {} vars
            url = url.Replace("QQQQ", GetQuadtreeFromXYZoom(x,y,zoom));
            url = url.Replace("XXXX", x.ToString());
            url = url.Replace("YYYY", y.ToString());
            url = url.Replace("ZZZZ", (17 - (int)zoom).ToString());
            url = url.Replace("{OSM_ZOOM}", ((int)zoom).ToString());
            url = url.Replace("{MS_QUADCODE}", quadcode);
            url = url.Replace("*", ((x+y+zoom) %4).ToString());
            return url;
        }
        static void Main(string[] args)
        {
            string url = BuildUrl("GoogleMap", 1, 1, 1);
            //return <a href="http://mt2.google.com/vt/lyrs=m@121&hl=en&x=1&y=1&z=1&s=Gali">http://mt2.google.com/vt/lyrs=m@121&hl=en&x=1&y=1&z=1&s=Gali</a>
        }
    }
}

例子中取出 google map ,在 zoom=1 及 x=1,y=1是的图片。
http://mt2.google.com/vt/lyrs=m@121&hl=en&x=1&y=1&z=1&s=Gali

下载工具  http://www.mapdigit.com/forum/viewthread.php?tid=43&extra=page%3D1 中文说明参见离线地图生成工具结构图离线地图生成工具使用方法

 

LWUIT引路蜂地图开发示例:放大、缩小

RasterMap的 zoomIn,zoomOut 用来放大缩小地图。 

package com.pstreets.gisengine.demo.lwuit;

//--------------------------------- IMPORTS ------------------------------------
import com.mapdigit.gis.geometry.GeoLatLng;
import com.mapdigit.gis.raster.MapType;

import com.pstreets.gisengine.demo.MapDemoLWUIT;
import com.sun.lwuit.Command;
import com.sun.lwuit.events.ActionEvent;

public class MapZoomLWUIT extends MapDemoLWUIT {

    private Command mapZoomInCommand;
    private Command mapZoomOutCommand;

    public void startApp() {
        init();
        canvas.setTitle("Map Zoom");
        canvas.setScrollable(false);

        mapZoomInCommand = new Command("Zoom In") {
            public void actionPerformed(ActionEvent evt) {
                map.zoomIn();
            }
        };

        mapZoomOutCommand = new Command("Zoom Out") {
            public void actionPerformed(ActionEvent evt) {
                map.zoomOut();
            }
        };

        canvas.addCommand(mapZoomInCommand);
        canvas.addCommand(mapZoomOutCommand);
        GeoLatLng center =  new GeoLatLng(32.0616667, 118.7777778);
        map.setCenter(center, 13, MapType.MICROSOFTCHINA);
        canvas.show();
    }
}

 

Blackberry引路蜂地图开发示例:叠加自定义图层

在开发应用的过程中,常常需要在地图上需绘制一点自定义的兴趣点或是自定义的几何图形。引路蜂地图包中RasterMap最终提供的基实就是一张图片。

protected void paint(Graphics g) {            
    map.paint(mapGraphics);            
 g.drawImage((Image) mapImage.getNativeImage(), 0, 0, 0);        
 //start drawing your own sharps or images.            
 ... … 
}

所以一个简单的方法是绘制完地图后,你可以使用任何绘图方法在地图绘制任何自定义的图形或是图象。
这里需要注意的是坐标变换,RasterMap采用的是经纬度坐标,而屏幕显示采用的屏幕坐标,RasterMap提供了坐标转换的方法:fromScreenPixelToLatLng 坐屏幕坐标转换成地图经纬度坐标。fromLatLngToScreenPixel 从经纬度坐标转换成屏幕坐标。
下面给出的例子是采用派生MapLayer子类的方法,RasterMap是 MapLayerContainer的子类,可以用来管理多个地图层。这些图层从下到上相当于透明纸一层一层叠加形成最终显示的地图。
例子中显示几个自定义兴趣点,和一个三角形,并中地图中心显示十字标。

//--------------------------------- PACKAGE ------------------------------------
package com.pstreets.gisengine.demo.rim;

//--------------------------------- IMPORTS ------------------------------------
import com.mapdigit.gis.MapLayer;
import com.mapdigit.gis.drawing.IGraphics;
import com.mapdigit.gis.geometry.GeoLatLng;
import com.mapdigit.gis.geometry.GeoPoint;
import com.mapdigit.gis.raster.MapType;
import com.pstreets.gisengine.demo.MapDemoRIM;

//[------------------------------ MAIN CLASS ----------------------------------]
/**
 * map overlay demo for Guidebee Map API on RIM platform.
 * <hr><b>&copy; Copyright 2011 Guidebee, Inc. All Rights Reserved.</b>
 * @version     1.00, 06/02/11
 * @author      Guidebee Pty Ltd.
 */
public class MapOverlayRIM extends MapDemoRIM {

    OverLayMapLayer mapLayer;
    /**
     * Entry point for application
     * @param args Command line arguments (not used)
     */
    public static void main(String[] args)
    {
        // Create a new instance of the application and make the currently
        // running thread the application's event dispatch thread.
        MapOverlayRIM theApp = new MapOverlayRIM();
        theApp.enterEventDispatcher();
    }

    public MapOverlayRIM() {
        init();
        pushScreen(canvas);
        GeoLatLng center = new GeoLatLng(32.0616667, 118.7777778);
        map.setCenter(center, 10, MapType.GOOGLECHINA);
        mapLayer = new OverLayMapLayer(canvas.getWidth(),
                canvas.getHeight());
        map.addMapLayer(mapLayer);
    }

    class OverLayMapLayer extends MapLayer {

        GeoLatLng pt1 = new GeoLatLng(32.345281, 118.84261);
        GeoLatLng pt2 = new GeoLatLng(32.05899, 118.62789);
        GeoLatLng pt3 = new GeoLatLng(32.011811, 118.798656);

        public OverLayMapLayer(int width, int height) {
            super(width, height);
        }

        public void paint(IGraphics graphics, int offsetX, int offsetY) {
            drawCursor(graphics);
            drawTriangle(graphics);
            drawPoint(graphics, pt1);
            drawPoint(graphics, pt2);
            drawPoint(graphics, pt3);

        }

        public void drawTriangle(IGraphics g) {
            GeoPoint ptOnScreen1 = map.fromLatLngToScreenPixel(pt1);
            GeoPoint ptOnScreen2 = map.fromLatLngToScreenPixel(pt2);
            GeoPoint ptOnScreen3 = map.fromLatLngToScreenPixel(pt3);
            g.setColor(0x0000FF);

            g.drawLine((int) ptOnScreen1.x, (int) ptOnScreen1.y,
                    (int) ptOnScreen2.x, (int) ptOnScreen2.y);
            g.drawLine((int) ptOnScreen2.x, (int) ptOnScreen2.y,
                    (int) ptOnScreen3.x, (int) ptOnScreen3.y);
            g.drawLine((int) ptOnScreen1.x, (int) ptOnScreen1.y,
                    (int) ptOnScreen3.x, (int) ptOnScreen3.y);
        }

        public void drawPoint(IGraphics g, GeoLatLng pt) {
            GeoPoint ptOnScreen = map.fromLatLngToScreenPixel(pt);
            int x = (int) ptOnScreen.x;
            int y = (int) ptOnScreen.y;
            g.setColor(0x00FF00);
            g.fillRect(x - 4, y - 4, 8, 8);

        }

        private void drawCursor(IGraphics g) {
            int x =getMapWidth()/2;
            int y =getMapHeight()/2 ;
            g.setColor(0x205020);
            g.drawRect(x - 4, y - 4, 8, 8);
            g.drawLine(x, y - 6, x, y - 2);
            g.drawLine(x, y + 6, x, y + 2);
            g.drawLine(x - 6, y, x - 2, y);
            g.drawLine(x + 6, y, x + 2, y);
        }
    }

}


 

Blackberry引路蜂地图开发示例:选择地图服务

引路蜂地图服务缺省使用Google地图服务,但你也可以选择其它地图服务,比方说当Google服务离线时,您可以选择MapAbc的地图服务,另外要注意的是中国地图是有偏移的。如果想使用无偏移的中国地图,一是采用地图偏移校正算法,另外一个是使用CloudMade地图服务。
所前所述,引路蜂地图开发包在设计时将地图图片显示和地图服务两部分设计成相对独立的两部分,Google中国地图图片,Bing中国地图图片,MapAbc中国地图图片是有偏移的地图图片,CloudMade(OpenStreet)中国地图图片是无偏移的。而Google中国地图服务,MapAbc中国地图服务是有偏移,CloudMade地图服务是无偏移的。所以在选择地图类型和地图服务类型时,要么都选择有偏移,要么都选择无偏移。否则地图在显示路径时或地址时就不匹配。 

 下面列表是合法的组合:

地图类型 MapType   地图服务类型 (DigitalMapService) 
GOOGLECHINA  GOOGLE_MAP_SERVICE 
MICROSOFTCHINA  GOOGLE_MAP_SERVICE 
MAPABCCHINA  GOOGLE_MAP_SERVICE 
OPENSTREETMAP  CLOUDMADE_MAP_SERVICE 
GOOGLECHINA  MAPABC_MAP_SERVICE 
MICROSOFTCHINA  MAPABC_MAP_SERVICE 
MAPABCCHINA  MAPABC_MAP_SERVICE 

下述示列地图类型使用MICROSOFTCHINA,而使用不同的地图服务时路径查询的情况。(南京到天津的路径) 

//--------------------------------- PACKAGE ------------------------------------
package com.pstreets.gisengine.demo.rim;

//--------------------------------- IMPORTS ------------------------------------
import com.mapdigit.gis.MapDirection;
import com.mapdigit.gis.geometry.GeoLatLng;
import com.mapdigit.gis.raster.MapType;
import com.mapdigit.gis.service.IRoutingListener;
import com.mapdigit.gis.service.DigitalMapService;
import com.pstreets.gisengine.demo.MapDemoRIM;
import net.rim.device.api.ui.component.Menu;
import net.rim.device.api.ui.MenuItem;

//[------------------------------ MAIN CLASS ----------------------------------]
/**
 *  Map routing demo for Guidebee Map API on RIM platform.
 * <hr><b>&copy; Copyright 2011 Guidebee, Inc. All Rights Reserved.</b>
 * @version     1.00, 10/02/11
 * @author      Guidebee Pty Ltd.
 */
public class MapServiceTypeRIM extends MapDemoRIM implements   
   IRoutingListener {

    /**
     * Entry point for application
     * @param args Command line arguments (not used)
     */
    public static void main(String[] args)
    {
        // Create a new instance of the application and make the currently
        // running thread the application's event dispatch thread.
        MapServiceTypeRIM theApp = new MapServiceTypeRIM();      
        theApp.enterEventDispatcher();
    }
   
    private MenuItem mapGetDirectionMenuItem = new MenuItem("Get Direction", 0, 0){
        public void run(){
            GeoLatLng latLng1=new GeoLatLng(32.0418381,118.7788905);
            GeoLatLng latLng2=new GeoLatLng(39.11643,117.180908);
            map.getDirections(new GeoLatLng[]{latLng1,latLng2});
        }
    };

    public MapServiceTypeRIM() {

        init();
        pushScreen(canvas);
        //map.setCurrentMapService(DigitalMapService.GOOGLE_MAP_SERVICE);
        //map.setCurrentMapService(DigitalMapService.MAPABC_MAP_SERVICE);
         map.setCurrentMapService(DigitalMapService.CLOUDMADE_MAP_SERVICE);
        map.setRoutingListener(this);
        GeoLatLng center = new GeoLatLng(32.0616667, 118.7777778);       
        map.setCenter(center, 13, MapType.MICROSOFTCHINA);
       
    }
 

    public void done(String arg0, MapDirection result) {
        if (result != null) {
            map.setMapDirection(result);
            //map.resize(result.getBound());
           // map.setZoom(6);
           map.setZoom(15);
           map.panTo(result.routes[0].startGeocode.point);
        }
    }
   
    protected void createMenu(Menu menu, int instance){
         menu.add(mapGetDirectionMenuItem);

   }
}

上图分别为三种地图服务返回的路径,Google 地图服务和MapAbc地图服务返回的结果基本相同,实际上Google 地图服务在中国的地图是来自于MapAbc。而CloudMade地图返回的结果似乎偏移了道路。这是因为Bing 中国地图是被偏移过的,而CloudMade返回的无偏移的结果。Google 地图服务和MapAbc地图服务返回的结果也是偏移过的,所以和偏移过的地图很“匹配”。

 

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

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

//--------------------------------- PACKAGE ------------------------------------
package com.pstreets.gisengine.demo.rim;

//--------------------------------- IMPORTS ------------------------------------
import com.mapdigit.gis.MapPoint;
import com.mapdigit.gis.geometry.GeoLatLng;
import com.mapdigit.gis.raster.MapType;
import com.mapdigit.gis.service.IReverseGeocodingListener;
import com.pstreets.gisengine.demo.MapDemoRIM;
import net.rim.device.api.ui.component.Menu;
import net.rim.device.api.ui.MenuItem;

//[------------------------------ MAIN CLASS ----------------------------------]
public class MapReverseGeocodingRIM extends MapDemoRIM implements
 IReverseGeocodingListener   {

    /**
     * Entry point for application
     * @param args Command line arguments (not used)
     */ 
    public static void main(String[] args)
    {
        // Create a new instance of the application and make the currently
        // running thread the application's event dispatch thread.
        MapReverseGeocodingRIM theApp = new MapReverseGeocodingRIM();       
        theApp.enterEventDispatcher();
    }
    
    private MenuItem mapFindAddressMenuItem = new MenuItem("Find Address", 0, 0){
        public void run(){
            map.getReverseLocations("32.061699,118.777802"); 
        }
    };

    public MapReverseGeocodingRIM() {

        init();
        pushScreen(canvas);
        map.setReverseGeocodingListener(this);
       GeoLatLng center = new GeoLatLng(32.0616667, 118.7777778);        
        map.setCenter(center, 13, MapType.MICROSOFTCHINA); 
        
    }

   
    public void done(String arg0, MapPoint[] result) {
        if (result != null) {
            map.panTo(result[0].getPoint());
        }
    }
    
    protected void createMenu(Menu menu, int instance){
         menu.add(mapFindAddressMenuItem);
 }
}

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