如何在iPhone中加载谷歌地图更快

时间:2009-09-10 03:25:40

标签: iphone google-maps maps

在我的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> 

2 个答案:

答案 0 :(得分:0)

看看这个答案:

Showing Driving Directions in MapKit

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

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

答案 1 :(得分:0)

你一定要看看是否可以切换到V3 of the Google Maps API。它专门设计用于在移动浏览器上快速加载。唯一的问题(也是一个很大的问题)是它还不支持方向。