0

在我的 iPhone 应用程序中,我正在将行车路线从捆绑的 html 页面加载到 WebView(因为我找不到将其直接加载到 MapKit 的方法),但是加载时间太长,有没有更好的怎么做?就像在 iPhone 默认地图应用程序中一样

代码 :

NSString *filePathString = [[NSBundle mainBundle] pathForResource:@"drive_index" ofType:@"html"];
NSMutableString *html = [[NSMutableString alloc] initWithContentsOfFile: filePathString];

[html replaceOccurrencesOfString: @"varLocation1" withString:loc1
                         options: NSLiteralSearch range: NSMakeRange(0, [html length])];

[html replaceOccurrencesOfString: @"varLocation2" withString:loc2
                         options: NSLiteralSearch range: NSMakeRange(0, [html length])];


NSURL *aURL = [NSURL fileURLWithPath:filePathString];
[webView loadHTMLString:html baseURL:aURL];

和html页面

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title>Google Maps JavaScript API Example: Simple Map</title>
<script src="http://maps.google.com/maps?file=api&amp;v=2&amp;sensor=false&amp;key=ABQIAAAAzr2EBOXUKnm_jVnk0OJI7xSosDVG8KKPE1-m51RBrvYughuyMxQ-i1QfUnH94QxWIa6N4U6MouMmBA"
        type="text/javascript"></script>
<script type="text/javascript">

var directionsPanel;
var directions; 
var location1="varLocation1";
var location2="varLocation2";

function initialize() {
  if (GBrowserIsCompatible()) {
  map = new GMap2(document.getElementById("map_canvas"));
  map.setCenter(new GLatLng(location1), 13);
  directionsPanel = document.getElementById("route");
  directions = new GDirections(map, directionsPanel);   
  directions.load('from: ' + location1 +' to: '+ location2 );
  }
}

</script> 

</head>
<body onload="initialize()" onunload="GUnload()">
<div id="map_canvas" style="width:divice-width ; height:350px ; float:top; border: 1px solid black;"></div>
<div id="route" style="width:divice-width; border; 1px solid black;"></div>

</body> 
</html> 
4

2 回答 2

0

看看这个答案:

在 MapKit 中显示行车路线

它说明了一种使用地图工具包(不包括行车路线)和直接在顶部覆盖线的方法。这是他们引用的网站:

http://spitzkoff.com/craig/?p=65

于 2009-09-10T05:21:17.327 回答
0

您绝对应该看看是否可以切换到Google Maps API 的 V3。它专门设计用于在移动浏览器上快速加载。唯一的问题(这是一个大问题)是它还不支持方向。

于 2009-09-10T05:50:04.723 回答