Search in sources :

Example 36 with Location

use of com.codename1.location.Location in project CodenameOne by codenameone.

the class MIDPLocationManager 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 37 with Location

use of com.codename1.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 38 with Location

use of com.codename1.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

ArrayList (java.util.ArrayList)18 Location (location.Location)17 Location (com.codename1.location.Location)5 IOException (java.io.IOException)5 Point (com.codename1.ui.geom.Point)4 Component (com.codename1.ui.Component)3 ActionEvent (com.codename1.ui.events.ActionEvent)3 ConnectionRequest (com.codename1.io.ConnectionRequest)2 BrowserComponent (com.codename1.ui.BrowserComponent)2 ActionListener (com.codename1.ui.events.ActionListener)2 QualifiedCoordinates (javax.microedition.location.QualifiedCoordinates)2 Paint (com.codename1.charts.compat.Paint)1 Point (com.codename1.charts.models.Point)1 XYSeries (com.codename1.charts.models.XYSeries)1 Orientation (com.codename1.charts.renderers.XYMultipleSeriesRenderer.Orientation)1 XYSeriesRenderer (com.codename1.charts.renderers.XYSeriesRenderer)1 BindTarget (com.codename1.cloud.BindTarget)1 CodenameOneImplementation (com.codename1.impl.CodenameOneImplementation)1 BufferedOutputStream (com.codename1.io.BufferedOutputStream)1 FileSystemStorage (com.codename1.io.FileSystemStorage)1