I just play with the Appcelerator Titanium platform for developing mobile applications.
My test application opens a webview pointing to an online page. This page uses the W3C Geolocation API to get the user's location.
These are my special permissions for android tiapp.xml:
<android xmlns:android="http://schemas.android.com/apk/res/android"> <manifest> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> <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_EXTRA_COMMANDS"/> </manifest> </android>
This is my javascript code to get the coordinates:
if (navigator.geolocation) { navigator.geolocation.getCurrentPosition(function(position){ $("#results").append('Longitude: ' + position.coords.longitude + '<br/>'); $("#results").append('Latitude: ' + position.coords.latitude + '<br/>'); }, function(error){ $("#results").append('An error ocurred ' + error.message); }); } else { $("#results").append('Geolocation not supported'); }
It seems that navigator.geolocation and navigator.geolocation.getCurrentPosition are defined, but delegation is not done anyway.
Question: how to make this work ?:-)
Thanks in advance.
Update: I found that the problem is that Android 2.x webview has its own implementation of navigator.geolocation. In accordance with this fix on the source code of the phone book.
Update 2:. I wrote a very small, full-featured Android application that opens a web client on the same web page and works great:
package com.sourcerebels; import android.app.Activity; import android.os.Bundle; import android.webkit.GeolocationPermissions.Callback; import android.webkit.WebChromeClient; import android.webkit.WebView; class MyClient extends WebChromeClient { @Override public void onGeolocationPermissionsShowPrompt(String origin, Callback callback) { callback.invoke(origin, true, false); } } public class TestWebClient extends Activity { WebView webView; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); webView = (WebView) findViewById(R.id.webView1); webView.getSettings().setJavaScriptEnabled(true); webView.getSettings().setGeolocationDatabasePath("/data/data/testWebClient"); webView.loadUrl("http://www.sourcerebels.com/index2.html"); webView.setWebChromeClient(new MyClient()); } }
Update 3 . I found this source from the gsiteub appcelerator website: https://github.com/appcelerator/titanium_mobile/blob/master/android/modules/ui/src/ti/modules/titanium/ui/widget/webview/TiWebChromeClient.java