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

GoogleMapsAPIのV3に切り替えることができるかどうかを確実に確認する必要があります。これは、モバイルブラウザにすばやく読み込まれるように特別に設計されています。唯一の問題(そしてそれは大きな問題です)は、それがまだ方向をサポートしていないということです。

于 2009-09-10T05:50:04.723 に答える
0

この答えを見てください:

MapKit で運転ルートを表示する

マップ キット (道順は含まれません) を使用し、その上に線を直接重ねる方法が記載されています。彼らが参照したサイトは次のとおりです。

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

于 2009-09-10T05:21:17.327 に答える