Question

dans mon application iPhone, je charge les indications routières vers une WebView à partir d'une page HTML fournie (car je ne trouve pas le moyen de le charger directement dans le MapKit), mais cela prend trop de temps à charger. Y at-il une meilleure façon de le faire? Comme dans l'application de carte par défaut de l'iPhone

code:

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];

et la page 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> 
Était-ce utile?

La solution

Regardez cette réponse:

Affichage des itinéraires dans MapKit

Cela indique un moyen d'utiliser le kit cartographique (qui n'inclut pas les indications de conduite) et de superposer les lignes directement au-dessus. Voici le site auquel ils font référence:

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

Autres conseils

Vous devriez absolument voir si vous pouvez passer à la V3 de l'API Google Maps . Il a été spécialement conçu pour se charger rapidement sur les navigateurs mobiles. Le seul problème (et c’est un problème majeur) est qu’il ne prend pas encore en charge les instructions.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top