Search in sources :

Example 21 with Location

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;
}
Also used : QualifiedCoordinates(javax.microedition.location.QualifiedCoordinates) Location(com.codename1.location.Location)

Example 22 with Location

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();
    }
}
Also used : SuccessCallback(com.codename1.util.SuccessCallback) ActionEvent(com.codename1.ui.events.ActionEvent) JSRef(com.codename1.ui.BrowserComponent.JSRef) IOException(java.io.IOException) Point(com.codename1.ui.geom.Point) JSRef(com.codename1.ui.BrowserComponent.JSRef) ActionListener(com.codename1.ui.events.ActionListener) BrowserComponent(com.codename1.ui.BrowserComponent) Location(com.codename1.location.Location)

Aggregations

Location (location.Location)17 ArrayList (java.util.ArrayList)16 Location (com.codename1.location.Location)5 IOException (java.io.IOException)3 Timer (java.util.Timer)2 TimerTask (java.util.TimerTask)2 QualifiedCoordinates (javax.microedition.location.QualifiedCoordinates)2 Geofence (com.codename1.location.Geofence)1 GeofenceListener (com.codename1.location.GeofenceListener)1 LocationListener (com.codename1.location.LocationListener)1 BrowserComponent (com.codename1.ui.BrowserComponent)1 JSRef (com.codename1.ui.BrowserComponent.JSRef)1 ActionEvent (com.codename1.ui.events.ActionEvent)1 ActionListener (com.codename1.ui.events.ActionListener)1 Point (com.codename1.ui.geom.Point)1 SuccessCallback (com.codename1.util.SuccessCallback)1 Date (java.util.Date)1