Posts Tagged ‘geolocation’

* Mobile Geolocation Implementations

Posted on August 19th, 2010 by Dave Johnson. Filed under Uncategorized, phonegap.


Today I found some time to take a look at the various mobile implementations of geolocation.

Below is a table showing the properties that the geolocation API uses on the various platforms. The W3C geolocation API for browsers specifies a PositionOptions interface that requires a maximum age, timeout and accuracy. Below that row is all of the mobile platforms that we are interested in for PhoneGap and the properties that they support in their native implementations. Some of them support a distance filter that will cause the device to only return geolocation positions if the location has changed by more than that distance while others also support an explicit interval for watching for location changes (note that on Android that interval is only a hint to let the device know how much power to use in getting a location - the position may be reported at an interval either shorter or longer than the specified interval).

I am probably going to be adding these two additional arguments to the PhoneGap PositionOptions and they can be used on platforms that support them.

Max age Timeout Accuracy Distance Interval
W3C X X X
BlackBerry maxAge timeout - - interval
iPhone - - desiredAccuracy distanceFilter -
Android - - - minDistance minTime
webOS maximumAge responseTime accuracy - -
WRT updateMaxAge updateTimeout - - updateInterval
Winphone - - DesiredAccuracy MovementThreshold

Image from cloneofsnake

Tags: , , , .



* BlackBerry PhoneGap Progress Report

Posted on December 6th, 2008 by Dave Johnson. Filed under phonegap.


BlackBerry PhoneGap
We had a PhoneGap sprint just over a week ago which was pretty successful for me and my BlackBerry ambitions as well as everyone else. Through that sprint and over the past week, despite some setbacks, I got the OS v4.5 installed on my phone and the simulator on my computer giving me access to a few new things but I was sad to find that a few other things were still sorely lacking that are pretty important for something like PhoneGap. Just so you know, OS v4.5 is the latest OS that will run on my Curve 8310 - 4.6 will run on the Bold, Pearl Flip and newer Curves while 4.7 works on the Storm. The two biggest gaffs by RIM are in the BlackBerry web browser for OS v4.5 where that the following rather important features are missing:

  1. You can’t pass function pointers to setTimeout.
  2. You can’t access DOM Nodes in any way shape or form (aside from form fields). So there is no getElementById or innerHTML on the resulting nodes. This make web application development a little bit difficult.
  3. There is no XMLHttpRequest object.
  4. While not really expected, there is no SQLite support
    anywhere on the phone as of yet, let alone the browser.

Anyhow, despite those setbacks on the v4.5 OS I did get the communication between the BlackBerry device and the web page all dialed now. Not only that but I have implemented the W3C geolocation API and am going to follow that same pattern for the other APIs. Check out the geolocation JavaScript interface as well as the platform specific implementation.

In the actual BlackBerry code there is lots of boiler plate stuff. The main hurdle was figuring what the best (or any) way to embed the browser in the application was and enable communication between JavaScript in the browser and the BlackBerry Java code. In the end I pretty much had to take the route of implementing the browser myself through the BrowserContentManager. This means that I have to implement lots of functionality, but it also means that I am in control of cookies and responsible for accepting them from JavaScript in the web page through the implementation of the browser fields RenderingApplication.eventOccurred method when the event type is EVENT_SET_HTTP_COOKIE and returning them to JavaScript by implementing the RenderingApplication.GetHTTPCookie method.

When the set cookie event occurs I parse out the cookies looking for one named bb_command and expect it to contain some JSON object (that is parsed with the J2ME port of a Java JSON lib) with a command property (like for opening maps or getting the GPS location) and some arguments (like points to plot on the map or how long to vibrate for). The case statement just looks like this:

switch (command)
{
  case 0:
    this._getLocation = true;
    this.startLocationUpdate();
    break;
  case 1:
    Invoke.invokeApplication(
      Invoke.APP_TYPE_MAPS,
      new MapsArguments(MapsArguments.ARG_LOCATION_DOCUMENT,
      getLocationDocument(args))
    );
    break;
  case 2:
    Invoke.invokeApplication(Invoke.APP_TYPE_CAMERA,
      new CameraArguments()
    );
    break;
  case 3:
    if (Alert.isVibrateSupported())
      Alert.startVibrate(getVibrateDuration(args));
    break;
  case 4:
    Invoke.invokeApplication(Invoke.APP_TYPE_PHONE,
      new PhoneArguments(PhoneArguments.ARG_CALL,
        getPhoneNumber(args)
      )
    );
    break;
  default:
}

where args is just a JSON string that the various methods like getPhoneNumber parse to get the args they want.

I will post some more specific code snippets like how to send text messages and so on very soon.

Tags: , , , , , , , , .