android - how to diplay geocalisation of an emulator? -
im using html5 technologie,i create small code display langitude , latitude of navigator ( pc navigator).
<!doctype html public "-//w3c//dtd html 4.01 transitional//en" "http://www.w3.org/tr/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1"> <title>insert title here</title> <style type="text/css"> body{ font-family: arial; font-size:0.8em; } div { margin:10px auto 100px; } code{ background-color:#ddd; margin:5px 0; padding:5px; font-size: 1.1em; display:block; width:50%; } h1{ margin:0px; padding:10px; padding-left:40px; font-family: trebuchet ms, arial; font-size:24px; font-style:italic; font-weight: normal; color:#444; } </style> <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true"> </script> <script type="text/javascript"> function getcoordposition(){ if(navigator.geolocation){ navigator.geolocation.getcurrentposition(function(position){ var latitude = position.coords.latitude; var longitude = position.coords.longitude; var altitude = position.coords.altitude; alert('latitude est ' + latitude +'*****' + 'logitude est ' + longitude); }); } } </script> </head> <body> <div id="coords"> <h1>les coordonnées</h1> <button onclick="getcoordposition();">obtenir les coordonnées</button> </div> </body> </html>
okay every thing fine.. want make same thing using android emulateur folow thoses steps: ( using eclipse indigo, android 4.2) 1. create new android project 2 create in asserts,www,index.html contains code put 3. mainactivity.java
package com.example.abc; import android.annotation.suppresslint; import android.app.activity; import android.os.bundle; import android.webkit.webchromeclient; import android.webkit.websettings; import android.webkit.webview; public class mainactivity extends activity { @suppresslint({ "setjavascriptenabled", "sdcardpath" }) @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); webview webview = (webview)findviewbyid(r.id.webview); webview.getsettings().setjavascriptenabled(true); webview.setwebchromeclient(new webchromeclient()); webview.getsettings().setdatabaseenabled(true); webview.getsettings().setdatabasepath("/data/data/com.example.abc/databases"); websettings websettings = webview.getsettings(); websettings.setjavascriptenabled(true); websettings.setgeolocationenabled(true); webview.getsettings().setappcacheenabled(true); webview.getsettings().setdatabaseenabled(true); webview.getsettings().setdomstorageenabled(true); webview.loadurl("file:///android_asset/www/index.html"); } }
4.the manifest file
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.abc" android:versioncode="1" android:versionname="1.0" > <uses-sdk android:minsdkversion="8" android:targetsdkversion="17" /> <uses-permission android:name="android.permission.internet" /> <uses-permission android:name="android.permission.access_gps" /> <uses-permission android:name="android.permission.access_assisted_gps" /> <uses-permission android:name="android.permission.access_location" /> <uses-permission android:name="android.permission.access_coarse_location" /> <uses-permission android:name="android.permission.access_fine_location" /> <application android:allowbackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/apptheme" > <activity android:name="com.example.abc.mainactivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.main" /> <category android:name="android.intent.category.launcher" /> </intent-filter> </activity> </application> </manifest>
5.the activitymain.xml
<relativelayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingbottom="@dimen/activity_vertical_margin" android:paddingleft="@dimen/activity_horizontal_margin" android:paddingright="@dimen/activity_horizontal_margin" android:paddingtop="@dimen/activity_vertical_margin" tools:context=".mainactivity" > <webview android:id="@+id/webview" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/hello_world" /> </relativelayout>
okay when run application nothing coordinates( longitude,latitude) 1 please me thx in advance