Pregunta

en mi aplicación para iPhone, estoy cargando las indicaciones para llegar a un WebView desde una página html empaquetada (porque no puedo encontrar una forma de cargarlo directamente en el MapKit), pero me lleva demasiado tiempo cargarlo, es ¿Hay alguna mejor manera de hacerlo? Como en la aplicación de mapas predeterminada de iPhone

código:

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

y la página 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> 
¿Fue útil?

Solución

Echa un vistazo a esta respuesta:

Mostrar indicaciones de conducción en MapKit

Dice una forma de usar el Kit de mapas (que no incluye instrucciones para conducir) y superponer líneas directamente en la parte superior. Aquí está el sitio al que hacen referencia:

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

Otros consejos

Definitivamente, debería ver si puede cambiar a V3 de la API de Google Maps . Fue diseñado específicamente para cargar rápidamente en navegadores móviles. El único problema (y es uno grande) es que aún no admite indicaciones.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top