在iPad/iPhone上使用必应地图

3

我该如何在iPad或iPhone商业应用程序中集成必应地图?

有人能帮帮我吗?


我在谷歌上找到了一篇相关的帖子。http://www.bing.com/community/site_blogs/b/maps/archive/2008/11/13/developing-virtual-earth-iphone-applications-with-objective-c.aspx 你已经尝试过了吗? - j_freyre
你想这样做的原因是什么?当然可以在Google地图客户端上叠加地图。我见过使用OpenStreetMap完成此操作,虽然没有看到Bing,但理论上应该可以实现! - ingh.am
2个回答

3
我从BING API写了一个JavaScript包装器来转换成ObjectiveC。
这不是最好的解决方案,但它能正常工作。
Objective-C提供了一种方法直接从代码中调用javascript。您可以使用UIWebView中的stringByEvaluatingJavaScriptFromString来调用所有js函数(缩放、设置地图类型等)。您的UIWebView必须是包含基本地图的HTML页面。 像这样:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
   <head>
      <title></title>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
      <script type="text/javascript" src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.2"></script>
      <script type="text/javascript">
         var map = null;

         function GetMap()
         {
            map = new VEMap('myMap');
            map.LoadMap(new VELatLong(45.46347, 9.19404), 10 ,'h' ,false);
            map.HideDashboard();
            map.SetMapStyle(VEMapStyle.Road);
            map.SetZoomLevel(10);
         }   
      </script>
   </head>
   <body onload="GetMap();">
      <div id='myMap' style="position:absolute; left:0px; top:0px; width:320px; height:460px;"></div>
   </body>
</html>

Bing参考 (http://www.microsoft.com/maps/isdk/ajax/)

经过一天的努力,您可以得到以下结果:

http://www.albertopasca.it/whiletrue/2010/10/iphone-microsoft-bing-map-iphone-ipad/

下面是一个包装好的js示例(其中map是您html页面上的JS变量):

- (void) setZoom:(int)level {
    [self stringByEvaluatingJavaScriptFromString:@"map.setZoom(%d);", level]];
}
- (void) setCenterPoint:(NSString*)point {
    [self stringByEvaluatingJavaScriptFromString:[@"map.setCenterPoint(%@);", point]];
}
- (void) zoomIn {
    [self stringByEvaluatingJavaScriptFromString:@"map.zoomIn();"];
}
- (void) zoomOut {
    [self stringByEvaluatingJavaScriptFromString:@"map.zoomOut();"];
}

你可以使用触摸手势等更多功能!

希望这能帮到你!

阿尔贝托。


Paska,你如何在这张地图上标出引脚并添加注释? - RK-
2
@Krishnan 我不记得了,但你可以在这里找到所有你需要的内容:http://www.microsoft.com/maps/isdk/ajax/ - elp
当在UIWebView中使用时,是否存在内存方面的问题? - objectiveCarlo
目前没有内存问题。 - elp

2

Bing Maps现在有一个iOS SDK,所以您可以在您的iOS应用程序中本地使用它:

新的Bing Maps iOS SDK


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接