Je veux charger la géolocalisation dans mon webview sur android 2.1. La géolocalisation fonctionne bien sur mon navigateur, mais elle échoue sur le webview.La géolocalisation ne peut pas être chargée sur le webview
public class WebPageLoader extends Activity implements GeolocationPermissions.Callback{
WebView webview;
String geoWebsiteURL = "http://hngu.naf.cs.hut.fi/current_location.html";
public WebPageLoader() {
}
/**
* Called with the activity is first created.
*/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
webview = (WebView) findViewById(R.id.webview);
webview.getSettings().setJavaScriptEnabled(true);
webview.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
webview.getSettings().setGeolocationEnabled(true); //seems like if i set this, the webview should prompt when I call navigator.geolocation.getCurrentPosition
GeoClient geo = new GeoClient();
webview.setWebChromeClient(geo);
String origin = ""; //how to get origin in correct format?
geo.onGeolocationPermissionsShowPrompt(origin, this); //obviously not how this is meant to be used but expected usage not documented
webview.loadUrl(geoWebsiteURL);
}
public void invoke(String origin, boolean allow, boolean remember) {
}
final class GeoClient extends WebChromeClient {
@Override
public void onGeolocationPermissionsShowPrompt(String origin,
Callback callback) {
// TODO Auto-generated method stub
super.onGeolocationPermissionsShowPrompt(origin, callback);
callback.invoke(origin, true, false);
}
}
}
Mon manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="net.Webview_Android"
android:versionCode="1"
android:versionName="1.0">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_LOCATION" />
<uses-library
android:name="com.google.android.maps" />
<uses-permission android:name="android.permission.ACCESS_GPS" />
<uses-permission android:name="android.permission.ACCESS_ASSISTED_GPS" />
<uses-sdk android:minSdkVersion="7" />
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".WebPageLoader"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Quand je lance l'application. Il affiche la carte google avec le marqueur. Cependant, il ne peut pas trouver l'emplacement actuel même si mon fichier html fonctionne bien. Aidez-moi, s'il vous plaît. Merci beaucoup.
Cela a fonctionné pour moi, merci beaucoup – Iorek