Como carregar Google Maps mais rápido no iPhone
-
05-07-2019 - |
Pergunta
no meu aplicativo iPhone Eu estou carregando as direcções de condução a um WebView a partir de uma página html empacotado (porque eu não posso encontrar uma maneira de carregá-lo diretamente para o MapKit), mas tomando muito tempo para carregar, é existe alguma maneira melhor de fazer isso? Como no aplicativo para iPhone mapa padrão
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];
ea 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&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>
Solução
Tenha um olhar para esta resposta:
Mostrando instruções de direção no MapKit
Ele diz que uma maneira de usar o Mapa Kit (que não inclui instruções de direção) e as linhas de sobreposição diretamente no topo. Aqui está o site que eles fazem referência:
Outras dicas
Você deve definitivamente ver se você pode alternar para V3 da API do Google Maps . Ele foi projetado especificamente para carregar rapidamente em navegadores móveis. O único problema (e é um grande problema) é que ele não suporta sentidos ainda.