J'ai un petit problème ... J'ai fait une application Android qui étend le webview. La page Webview Html avec une carte comme ceci: Map example, c'était aussi ici que j'ai eu mon inspiration. Ma méthode onCreate ressemble à ceci:Lors de l'obtention de la localisation GPS, charger une autre URL
super.onCreate(savedInstanceState);
//Removes the title bar in the application
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);
//Creation of the Webview found in the XML Layout file
browserView = (WebView)findViewById(R.id.webkit);
//Removes both vertical and horizontal scroll bars
browserView.setVerticalScrollBarEnabled(false);
browserView.setHorizontalScrollBarEnabled(false);
myLocationManager=(LocationManager)getSystemService(Context.LOCATION_SERVICE);
//Enable Javascripts
url = "http://www.my-homepage.dk/map_example.html";
browserView.getSettings().setJavaScriptEnabled(true);
//The website which is wrapped to the webview
browserView.loadUrl(url);
Alors, quand mon application obtient une position GPS, il appelle cette méthode:
LocationListener onLocationChange=new LocationListener() {
public void onLocationChanged(Location location) {
StringBuilder buf=new StringBuilder(url);
buf.append("?");
buf.append("lon=");
buf.append(String.valueOf(location.getLongitude()));
buf.append("&");
buf.append("lat=");
buf.append(String.valueOf(location.getLatitude()));
browserView.loadUrl(buf.toString());
}
Il charge fondamentalement juste une autre URL .... Mais, mon problème est, 1. il garde le site web original "image de la carte", j'ai imaginé qu'il "décharger" la page, et 2. Lorsque le second url est chargé, il faut beaucoup de temps avant qu'il soit fini, et quand je teste sur mon HTC Desire, il ne montre parfois pas la deuxième page chargée (la carte avec l'emplacement) avant qu'il éteigne l'écran et se verrouille, ou si je sors et dans l'application, cela aide parfois trop ...
Espoir vous pouvez aider :)
Vous pouvez essayer browserView.clearView() avant de charger une nouvelle URL. – bhups
Cela ne fonctionne pas ... :( – Roskvist