Vote count:
0
I made an app that uses google maps API v3 opening a HTML with a javascript saved in the assets. I also set the cache of the app to be able to see the maps even offline. It is working fine.
In the map, when ready, I draw a polyline and markers with 2D GPS data from a CSV file. It again works perfectly when online.
However, when offline, "sometimes" the polyline is shown, and sometimes it isn't. Like if the polyline/marks are hidden by the map itself, randomly. What is it happening? How to make this reliable?
About my code: My HTML
has the javascript inside. From android, I call the HTML page with a webview (code below). After the page is loaded, I load the track calling a method in the javascript with:
myWebView.loadUrl("javascript:loadtrackfile(\""+TrackFile+"\")");
Through the Internet, the page also works, and I pass the address as:
http://...../map.html?track=TrackFile
(the only way to pass TrackFile
to the webview was with a myWebView.setWebViewClient({})
. Maybe there is a better way?
My webview code is below.
Any clues??
Thanks!
L
The webview code:
public void onCreate(final Bundle onOreintChange) {
super.onCreate(onOreintChange);
ave_preferences = PreferenceManager.getDefaultSharedPreferences(this);
if (ave_preferences.getBoolean("fullscreen", false)) setTheme(R.style.MyTheme);
setContentView(R.layout.viewmap);
cachedir = AveActivity.DOWNS + "/cache";
String maphtml = "file:///android_asset/map.html";
Bundle extras = getIntent().getExtras();
if (extras != null) TrackFile = extras.getString("track");
myWebView = (WebView) findViewById(R.id.webviewmap);
ws = myWebView.getSettings();
ws.setUserAgentString(ws.getUserAgentString() + " AveWebview");
ws.setJavaScriptEnabled(true);
///// Cache to Internal SD (thanks to AveSetExtCache.java class)
ws.setAppCacheMaxSize( 500 * 1024 * 1024 ); // 500MB // DEPRECATED IN API 18
ws.setAllowFileAccess(true);
ws.setAppCacheEnabled(true);
ws.setDatabaseEnabled(true);
ws.setDomStorageEnabled(true);
boolean online = Downloads.isConnected(this, ave_preferences.getBoolean("wifionly", true));
ws.setCacheMode((online) ? WebSettings.LOAD_CACHE_ELSE_NETWORK : WebSettings.LOAD_CACHE_ONLY);
///// Geolocation and pass TrackFile to the JS (after page is loaded)
myWebView.setWebViewClient(new WebViewClient() {
@Override
public void onPageFinished(WebView view, String url) {
myWebView.loadUrl("javascript:loadtrackfile(\""+TrackFile+"\")");
}
});
myWebView.loadUrl(maphtml);
}
@Override
public void onDestroy() {
super.onDestroy();
if (ave_preferences.getBoolean("myposition", false)) {
ws.setGeolocationEnabled(false);
myWebView.loadUrl("javascript:toggleGeoLocation()");
}
finish();
}
}
Aucun commentaire:
Enregistrer un commentaire