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();
}
Aggregations