use of location.Location in project CodenameOne by codenameone.
the class RIMLocationManager method convert.
private Location convert(javax.microedition.location.Location loc) {
QualifiedCoordinates coor = loc.getQualifiedCoordinates();
Location retVal = new Location();
retVal.setAccuracy(coor.getHorizontalAccuracy());
retVal.setAltitude(coor.getAltitude());
if (currentCoordinates != null) {
retVal.setDirection(coor.azimuthTo(currentCoordinates));
}
retVal.setLatitude(coor.getLatitude());
retVal.setLongitude(coor.getLongitude());
retVal.setTimeStamp(loc.getTimestamp());
retVal.setVelocity(loc.getSpeed());
currentCoordinates = coor;
return retVal;
}
use of location.Location in project codenameone-google-maps by codenameone.
the class MapContainer method initBrowserComponent.
private void initBrowserComponent(String htmlApiKey) {
if (debug) {
Log.e(new RuntimeException("Initializing Browser Component. This stack trace is just for tracking purposes. It is NOT a real exception"));
}
// System.out.println("About to check location");
Location loc = LocationManager.getLocationManager().getLastKnownLocation();
try {
// if (true)return;
// System.out.println("About to load map text");
String str = Util.readToString(Display.getInstance().getResourceAsStream(null, "/com_codename1_googlemaps_MapContainer.html"));
// System.out.println("Map text: "+str);
str = StringUtil.replaceAll(str, "YOUR_API_KEY", htmlApiKey);
// System.out.println("Finished setting API key");
str = StringUtil.replaceAll(str, "//origin = MAPCONTAINER_ORIGIN", "origin = {lat: " + loc.getLatitude() + ", lng: " + loc.getLongitude() + "};");
// System.out.println("Finished setting origin");
internalBrowser.setPage(str, "/");
if (debug) {
Log.e(new RuntimeException("Adding onLoad Listener. This stack trace is just for tracking purposes. It is NOT a real exception"));
}
internalBrowser.addWebEventListener("onLoad", new ActionListener() {
public void actionPerformed(ActionEvent evt) {
if (debug) {
Log.e(new RuntimeException("Inside onLoad Listener. This stack trace is just for tracking purposes. It is NOT a real exception"));
}
// JavascriptContext ctx = new JavascriptContext(internalBrowser);
// browserBridge.ctx = ctx;
internalBrowser.execute("com_codename1_googlemaps_MapContainer = {}");
internalBrowser.addJSCallback("com_codename1_googlemaps_MapContainer.fireTapEvent = function(x,y){callback.onSuccess(x+','+y)};", new SuccessCallback<BrowserComponent.JSRef>() {
public void onSucess(BrowserComponent.JSRef value) {
String[] parts = Util.split(value.getValue(), ",");
int x = new Double(Double.parseDouble(parts[0])).intValue();
int y = new Double(Double.parseDouble(parts[1])).intValue();
fireTapEvent(x, y);
}
});
internalBrowser.addJSCallback("com_codename1_googlemaps_MapContainer.fireLongPressEvent = function(x,y){callback.onSuccess(x+','+y)};", new SuccessCallback<BrowserComponent.JSRef>() {
public void onSucess(BrowserComponent.JSRef value) {
String[] parts = Util.split(value.getValue(), ",");
int x = new Double(Double.parseDouble(parts[0])).intValue();
int y = new Double(Double.parseDouble(parts[1])).intValue();
fireLongPressEvent(x, y);
}
});
internalBrowser.addJSCallback("com_codename1_googlemaps_MapContainer.fireMapChangeEvent = function(zoom,lat,lon){callback.onSuccess(zoom+','+lat+','+lon)};", new SuccessCallback<BrowserComponent.JSRef>() {
public void onSucess(BrowserComponent.JSRef value) {
String[] parts = Util.split(value.getValue(), ",");
int zoom = Integer.parseInt(parts[0]);
double lat = Double.parseDouble(parts[1]);
double lon = Double.parseDouble(parts[2]);
fireMapListenerEvent(zoom, lat, lon);
}
});
internalBrowser.addJSCallback("com_codename1_googlemaps_MapContainer.fireMarkerEvent = function(id){callback.onSuccess(id)};", new SuccessCallback<BrowserComponent.JSRef>() {
public void onSucess(BrowserComponent.JSRef value) {
fireMarkerEvent(value.getInt());
}
});
internalBrowser.execute("callback.onSuccess(com_codename1_googlemaps_MapContainer_bridge)", new SuccessCallback<BrowserComponent.JSRef>() {
public void onSucess(BrowserComponent.JSRef value) {
if ("null".equals(value.getValue()) || value.getJSType() == BrowserComponent.JSType.UNDEFINED) {
internalBrowser.execute("com_codename1_googlemaps_MapContainer_onReady=function(bridge){callback.onSuccess(bridge)};", new SuccessCallback<BrowserComponent.JSRef>() {
public void onSucess(BrowserComponent.JSRef value) {
browserBridge.ready = true;
}
});
} else {
browserBridge.ready = true;
}
}
});
// /System.out.println("Bridge is ready");
if (debug) {
Log.p("About to fire browserBridge.ready(null) event to kick things off");
}
browserBridge.ready(null);
}
});
return;
} catch (IOException ex) {
ex.printStackTrace();
}
}
Aggregations