giovedì 17 settembre 2009

Geolocation

Keychain_team is actually working on a maps mashup (JooinK) based on the google maps api.
During the development we faced the problem of geolocate the remote user.

We looked a lot around the web and we found that it is possible
to obtain the position of the remote user accessing the "google
loader" ClientLocation field, unfortunately appear not possible to do
this directly through gwt's maps api but defining a jni function


private static native LatLng UserLocation() /*-{
if( $wnd.google ) {
if( $wnd.google.loader ) {
if ($wnd.google.loader.ClientLocation){
var center = new $wnd.google.maps.LatLng(
$wnd.google.loader.ClientLocation.latitude,
$wnd.google.loader.ClientLocation.longitude
);
return center;
}
}
}
return null;
}-*/;


and then calling the native method


LatLng userDefaultLocation = UserDefaultLocation();


We get the LatLng position of the user
Do not forget to load google's jsapi, e.g. putting in the head of your html file


<script type="text/javascript"
src="http://www.google.com/jsapi">
</script>


you will find soon the complete project on http://www.keychain.it

That's all folk!!

Nessun commento:

Posta un commento