Search in sources :

Example 6 with Marker

use of org.mapsforge.map.layer.overlay.Marker in project satstat by mvglasow.

the class MapSectionFragment method onLocationChanged.

/**
 * Called when a new location is found by a registered location provider.
 * Stores the location and updates GPS display and map view.
 */
public void onLocationChanged(Location location) {
    // location from that provider as stale
    if (Double.isNaN(location.getLatitude()) || Double.isNaN(location.getLongitude())) {
        markLocationAsStale(providerLocations.get(location.getProvider()));
        applyLocationProviderStyle(this.getContext(), location.getProvider(), Const.LOCATION_PROVIDER_GRAY);
        return;
    }
    if (providerLocations.containsKey(location.getProvider()))
        providerLocations.put(location.getProvider(), new Location(location));
    LatLong latLong = new LatLong(location.getLatitude(), location.getLongitude());
    Circle circle = mapCircles.get(location.getProvider());
    Marker marker = mapMarkers.get(location.getProvider());
    if (circle != null) {
        circle.setLatLong(latLong);
        if (location.hasAccuracy()) {
            circle.setVisible(true);
            circle.setRadius(location.getAccuracy());
        } else {
            Log.d("MainActivity", "Location from " + location.getProvider() + " has no accuracy");
            circle.setVisible(false);
        }
    }
    if (marker != null) {
        marker.setLatLong(latLong);
        marker.setVisible(true);
    }
    applyLocationProviderStyle(this.getContext(), location.getProvider(), null);
    Runnable invalidator = providerInvalidators.get(location.getProvider());
    if (invalidator != null) {
        providerInvalidationHandler.removeCallbacks(invalidator);
        providerInvalidationHandler.postDelayed(invalidator, PROVIDER_EXPIRATION_DELAY);
    }
    // redraw, move locations into view and zoom out as needed
    if ((circle != null) || (marker != null) || (invalidator != null))
        updateMap();
}
Also used : Circle(org.mapsforge.map.layer.overlay.Circle) Marker(org.mapsforge.map.layer.overlay.Marker) LatLong(org.mapsforge.core.model.LatLong) Location(android.location.Location)

Aggregations

Marker (org.mapsforge.map.layer.overlay.Marker)6 Drawable (android.graphics.drawable.Drawable)4 Bitmap (org.mapsforge.core.graphics.Bitmap)4 LatLong (org.mapsforge.core.model.LatLong)4 Location (android.location.Location)3 Context (android.content.Context)2 Intent (android.content.Intent)2 Resources (android.content.res.Resources)2 TypedArray (android.content.res.TypedArray)2 Window (android.view.Window)2 Circle (org.mapsforge.map.layer.overlay.Circle)2 Manifest (android.Manifest)1 Activity (android.app.Activity)1 PackageManager (android.content.pm.PackageManager)1 Color (android.graphics.Color)1 LocationListener (android.location.LocationListener)1 LocationManager (android.location.LocationManager)1 Uri (android.net.Uri)1 Bundle (android.os.Bundle)1 VibrationEffect (android.os.VibrationEffect)1