En ce qui concerne ce tutoriel WebView, en particulier cette méthodeAndroid WebView
private void setupWebView(){
String MAP_URL = "http://gmaps-samples.googlecode.com/svn/trunk/articles-android-webmap/simple-android-map.html";
String centerURL = "javascript:centerAt(" + mostRecentLocation.getLatitude() + ","+ mostRecentLocation.getLongitude()+ ")";
webView = (WebView) findViewById(R.id.webview);
webView.getSettings().setJavaScriptEnabled(true);
//Wait for the page to load then send the location information
webView.setWebViewClient(new WebViewClient(){
@Override
public void onPageFinished(WebView view, String url){
webView.loadUrl(centerURL);
}
});
webView.loadUrl(MAP_URL);
}
J'ai remarqué que si je place le webView.loadUrl(centerURL);
directement après webView.loadUrl(MAP_URL);
comme celui-ci
private void setupWebView(){
String MAP_URL = "http://gmaps-samples.googlecode.com/svn/trunk/articles-android-webmap/simple-android-map.html";
String centerURL = "javascript:centerAt(" + mostRecentLocation.getLatitude() + "," + mostRecentLocation.getLongitude()+ ")";
webView = (WebView) findViewById(R.id.webview);
webView.getSettings().setJavaScriptEnabled(true);
//Wait for the page to load then send the location information
webView.setWebViewClient(new WebViewClient(){
@Override
public void onPageFinished(WebView view, String url){
//DO NOTHING
}
});
webView.loadUrl(MAP_URL);
webView.loadUrl(centerURL);
}
il ne fonctionne plus . Donc, la méthode javascript centreAt(..)
est contenue dans la MAP_URL
.
Je me demande si la méthode webView.loadUrl(..)
retourne avant que l'URL ait été réellement chargée. Cela ressemble à cela car la méthode supérieure attend qu'elle se charge complètement avant d'exécuter le javascript
Groan .... Je viens de perdre toute la journée pour découvrir que. Tant pis. Bravo pour confirmer Peter. – Tim