Skip to content

Commit

Permalink
Fixed to BlackBerry native code for GeoLocation functionality.
Browse files Browse the repository at this point in the history
  • Loading branch information
Fil Maj committed Nov 28, 2009
1 parent 72c71a4 commit 1126195
Showing 1 changed file with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import net.rim.blackberry.api.invoke.Invoke;
import net.rim.blackberry.api.invoke.MapsArguments;

import com.nitobi.phonegap.PhoneGap;
import com.nitobi.phonegap.api.Command;
import com.nitobi.phonegap.model.Position;

Expand All @@ -44,24 +45,26 @@ public class GeoLocationCommand implements Command {
private static final int MAP_COMMAND = 0;
private static final int STOP_COMMAND = 1;
private static final int START_COMMAND = 2;
private static final int CHECK_COMMAND = 3;
private static final int CAPTURE_INTERVAL = 5;
private static final String CODE = "PhoneGap=location";
private static final String GEO_NS = "navigator.geolocation.";
private static final String GEO_STOP = GEO_NS + "started = false;" + GEO_NS + "lastPosition = null;";
private static final String GEO_START = GEO_NS + "started = true;";
private static final String GEO_CHECK = GEO_NS + "setLocation(";
private static final String GEO_ERROR = GEO_NS + "setError(";
private static final String GEO_SET_LOCATION = GEO_NS + "setLocation(";
private static final String GEO_SET_ERROR = GEO_NS + "setError(";
private static final String FUNC_SUF = ");";

private static final String ERROR_UNAVAILABLE = "'GPS unavailable on this device.'";
private static final String ERROR_OUTOFSERVICE = "'GPS is out of service on this device.'";

private PhoneGap berryGap;

private Position position;
private boolean availableGPS = true;
private LocationProvider locationProvider;

public GeoLocationCommand() {
public GeoLocationCommand(PhoneGap phoneGap) {
this.berryGap = phoneGap;
try {
locationProvider = LocationProvider.getInstance(null);
// Passing null as the parameter is equal to passing a Criteria that has all fields set to the default values,
Expand Down Expand Up @@ -104,7 +107,6 @@ public String execute(String instruction) {
return GEO_STOP;
case START_COMMAND: locationProvider.setLocationListener(new LocationListenerImpl(this), CAPTURE_INTERVAL, 1, 1);
return GEO_START;
case CHECK_COMMAND: if (position != null) return GEO_CHECK + position.toJavascript() + FUNC_SUF;
}
return null;
}
Expand All @@ -118,7 +120,6 @@ private int getCommand(String instruction) {
if ("map".equals(command)) return MAP_COMMAND;
if ("stop".equals(command)) return STOP_COMMAND;
if ("start".equals(command)) return START_COMMAND;
if ("check".equals(command)) return CHECK_COMMAND;
return -1;
}

Expand All @@ -132,10 +133,11 @@ private void updateLocation(double lat, double lng, float altitude, float accura
position.setHeading(heading);
position.setVelocity(speed);
position.setTimestamp(time);
berryGap.pendingResponses.addElement(GEO_SET_LOCATION + position.toJavascript() + FUNC_SUF);
}

private String setError(String error) {
return GEO_ERROR + error + FUNC_SUF;
return GEO_SET_ERROR + error + FUNC_SUF;
}

private String getLocationDocument() {
Expand Down

0 comments on commit 1126195

Please sign in to comment.