在我的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];
<!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&v=2&sensor=false&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>
答案 0 :(得分:0)
答案 1 :(得分:0)
你一定要看看是否可以切换到V3 of the Google Maps API。它专门设计用于在移动浏览器上快速加载。唯一的问题(也是一个很大的问题)是它还不支持方向。