use of net.osmand.Location in project Osmand by osmandapp.
the class DashLocationFragment method updateAllWidgets.
public void updateAllWidgets() {
DashboardOnMap d = dashboard;
if (d == null) {
return;
}
float head = d.getHeading();
float mapRotation = d.getMapRotation();
LatLon mw = d.getMapViewLocation();
Location l = d.getMyLocation();
boolean mapLinked = d.isMapLinkedToLocation() && l != null;
LatLon myLoc = l == null ? null : new LatLon(l.getLatitude(), l.getLongitude());
boolean useCenter = !mapLinked;
LatLon loc = (useCenter ? mw : myLoc);
float h = useCenter ? -mapRotation : head;
lastUpdatedLocation = loc;
for (DashLocationView lv : distances) {
updateLocationView(useCenter, loc, h, lv.arrow, lv.arrowResId, lv.txt, lv.loc, screenOrientation, getMyApplication(), getActivity(), lv.paint);
}
}
use of net.osmand.Location in project Osmand by osmandapp.
the class IntermediatePointsDialog method applySortTargets.
private static void applySortTargets(AlertDialog dlg, final Activity activity, final List<TargetPoint> intermediates, final TIntArrayList originalPositions, final ArrayAdapter<TargetPoint> listadapter, final ProgressBar pb, final TextView textInfo) {
dlg.setOnShowListener(new OnShowListener() {
@Override
public void onShow(DialogInterface dialog) {
((AlertDialog) dialog).getButton(AlertDialog.BUTTON_NEUTRAL).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new AsyncTask<Void, Void, int[]>() {
protected void onPreExecute() {
pb.setVisibility(View.VISIBLE);
textInfo.setVisibility(View.VISIBLE);
}
protected int[] doInBackground(Void[] params) {
OsmandApplication app = (OsmandApplication) activity.getApplication();
Location cll = app.getLocationProvider().getLastKnownLocation();
ArrayList<TargetPoint> lt = new ArrayList<TargetPoint>(intermediates);
TargetPoint start;
if (cll != null) {
LatLon ll = new LatLon(cll.getLatitude(), cll.getLongitude());
start = TargetPoint.create(ll, null);
} else if (app.getTargetPointsHelper().getPointToStart() != null) {
TargetPoint ps = app.getTargetPointsHelper().getPointToStart();
LatLon ll = new LatLon(ps.getLatitude(), ps.getLongitude());
start = TargetPoint.create(ll, null);
// } else if(activity instanceof MapActivity) {
// LatLon ll = new LatLon(((MapActivity) activity).getMapView().getLatitude(), ((MapActivity) activity).getMapView().getLongitude());
// start = TargetPoint.create(ll, null);
} else {
start = lt.get(0);
}
TargetPoint end = lt.remove(lt.size() - 1);
ArrayList<LatLon> al = new ArrayList<LatLon>();
for (TargetPoint p : lt) {
al.add(p.point);
}
return new TspAnt().readGraph(al, start.point, end.point).solve();
}
protected void onPostExecute(int[] result) {
pb.setVisibility(View.GONE);
List<TargetPoint> alocs = new ArrayList<TargetPoint>();
TIntArrayList newOriginalPositions = new TIntArrayList();
for (int i = 0; i < result.length; i++) {
if (result[i] > 0) {
TargetPoint loc = intermediates.get(result[i] - 1);
alocs.add(loc);
newOriginalPositions.add(originalPositions.get(intermediates.indexOf(loc)));
}
}
intermediates.clear();
intermediates.addAll(alocs);
originalPositions.clear();
originalPositions.addAll(newOriginalPositions);
listadapter.notifyDataSetChanged();
}
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, new Void[0]);
}
});
}
});
}
use of net.osmand.Location in project Osmand by osmandapp.
the class MapActivity method readLocationToShow.
public void readLocationToShow() {
if (!getDashboard().isVisible()) {
mapLayers.getMapControlsLayer().showMapControlsIfHidden();
}
LatLon cur = new LatLon(mapView.getLatitude(), mapView.getLongitude());
LatLon latLonToShow = settings.getAndClearMapLocationToShow();
PointDescription mapLabelToShow = settings.getAndClearMapLabelToShow(latLonToShow);
Object toShow = settings.getAndClearObjectToShow();
boolean editToShow = settings.getAndClearEditObjectToShow();
int status = settings.isRouteToPointNavigateAndClear();
String searchRequestToShow = settings.getAndClearSearchRequestToShow();
if (status != 0) {
// always enable and follow and let calculate it (i.e.GPS is not accessible in a garage)
Location loc = new Location("map");
loc.setLatitude(mapView.getLatitude());
loc.setLongitude(mapView.getLongitude());
getMapActions().enterRoutePlanningModeGivenGpx(null, null, null, true, true);
if (dashboardOnMap.isVisible()) {
dashboardOnMap.hideDashboard();
}
}
if (searchRequestToShow != null) {
showQuickSearch(searchRequestToShow);
}
if (latLonToShow != null) {
if (dashboardOnMap.isVisible()) {
dashboardOnMap.hideDashboard();
}
// remember if map should come back to isMapLinkedToLocation=true
mapViewTrackingUtilities.setMapLinkedToLocation(false);
if (mapLabelToShow != null && !mapLabelToShow.contextMenuDisabled()) {
mapContextMenu.setMapCenter(latLonToShow);
mapContextMenu.setMapPosition(mapView.getMapPosition());
mapContextMenu.setCenterMarker(true);
RotatedTileBox tb = mapView.getCurrentRotatedTileBox().copy();
LatLon prevCenter = tb.getCenterLatLon();
double border = 0.8;
int tbw = (int) (tb.getPixWidth() * border);
int tbh = (int) (tb.getPixHeight() * border);
tb.setPixelDimensions(tbw, tbh);
tb.setLatLonCenter(latLonToShow.getLatitude(), latLonToShow.getLongitude());
tb.setZoom(ZOOM_LABEL_DISPLAY);
while (!tb.containsLatLon(prevCenter.getLatitude(), prevCenter.getLongitude()) && tb.getZoom() > MIN_ZOOM_LABEL_DISPLAY) {
tb.setZoom(tb.getZoom() - 1);
}
// mapContextMenu.setMapZoom(settings.getMapZoomToShow());
mapContextMenu.setMapZoom(tb.getZoom());
if (toShow instanceof GpxDisplayItem) {
TrackDetailsMenu trackDetailsMenu = mapLayers.getMapControlsLayer().getTrackDetailsMenu();
trackDetailsMenu.setGpxItem((GpxDisplayItem) toShow);
trackDetailsMenu.show();
} else if (MapRouteInfoMenu.isVisible()) {
mapContextMenu.showMinimized(latLonToShow, mapLabelToShow, toShow);
mapLayers.getMapControlsLayer().getMapRouteInfoMenu().updateMenu();
MapRouteInfoMenu.showLocationOnMap(this, latLonToShow.getLatitude(), latLonToShow.getLongitude());
} else if (toShow instanceof QuadRect) {
QuadRect qr = (QuadRect) toShow;
mapView.fitRectToMap(qr.left, qr.right, qr.top, qr.bottom, (int) qr.width(), (int) qr.height(), 0);
} else if (toShow instanceof NewGpxPoint) {
NewGpxPoint newGpxPoint = (NewGpxPoint) toShow;
QuadRect qr = newGpxPoint.getRect();
mapView.fitRectToMap(qr.left, qr.right, qr.top, qr.bottom, (int) qr.width(), (int) qr.height(), 0);
getMapLayers().getContextMenuLayer().enterAddGpxPointMode(newGpxPoint);
} else if (toShow instanceof NewGpxData) {
NewGpxData newGpxData = (NewGpxData) toShow;
QuadRect qr = newGpxData.getRect();
mapView.fitRectToMap(qr.left, qr.right, qr.top, qr.bottom, (int) qr.width(), (int) qr.height(), 0);
MeasurementEditingContext editingContext = new MeasurementEditingContext();
editingContext.setNewGpxData(newGpxData);
MeasurementToolFragment.showInstance(getSupportFragmentManager(), editingContext);
} else {
mapContextMenu.show(latLonToShow, mapLabelToShow, toShow);
}
if (editToShow) {
mapContextMenu.openEditor();
}
} else if (!latLonToShow.equals(cur)) {
mapView.getAnimatedDraggingThread().startMoving(latLonToShow.getLatitude(), latLonToShow.getLongitude(), settings.getMapZoomToShow(), true);
}
}
}
use of net.osmand.Location in project Osmand by osmandapp.
the class GeocodingLookupService method geocode.
private boolean geocode(final LatLon latLon) {
Location loc = new Location("");
loc.setLatitude(latLon.getLatitude());
loc.setLongitude(latLon.getLongitude());
return app.getLocationProvider().getGeocodingResult(loc, new ResultMatcher<GeocodingResult>() {
@Override
public boolean publish(GeocodingResult object) {
String result = null;
if (object != null) {
OsmandSettings settings = app.getSettings();
String lang = settings.MAP_PREFERRED_LOCALE.get();
boolean transliterate = settings.MAP_TRANSLITERATE_NAMES.get();
String geocodingResult = "";
double relevantDistance = -1;
if (object.building != null) {
String bldName = object.building.getName(lang, transliterate);
if (!Algorithms.isEmpty(object.buildingInterpolation)) {
bldName = object.buildingInterpolation;
}
geocodingResult = object.street.getName(lang, transliterate) + " " + bldName + ", " + object.city.getName(lang, transliterate);
} else if (object.street != null) {
geocodingResult = object.street.getName(lang, transliterate) + ", " + object.city.getName(lang, transliterate);
relevantDistance = object.getDistanceP();
} else if (object.city != null) {
geocodingResult = object.city.getName(lang, transliterate);
} else if (object.point != null) {
RouteDataObject rd = object.point.getRoad();
String sname = rd.getName(lang, transliterate);
if (Algorithms.isEmpty(sname)) {
sname = "";
}
String ref = rd.getRef(lang, transliterate, true);
if (!Algorithms.isEmpty(ref)) {
if (!Algorithms.isEmpty(sname)) {
sname += ", ";
}
sname += ref;
}
geocodingResult = sname;
relevantDistance = object.getDistanceP();
}
result = geocodingResult;
if (relevantDistance == -1) {
relevantDistance = object.getDistance();
}
if (!Algorithms.isEmpty(result) && relevantDistance > 100) {
result = app.getString(R.string.shared_string_near) + " " + result;
}
}
lastFoundAddress = result;
searchDone = true;
return true;
}
@Override
public boolean isCancelled() {
return !hasAnyRequest(latLon);
}
});
}
use of net.osmand.Location in project Osmand by osmandapp.
the class DayNightHelper method getSunriseSunset.
public SunriseSunset getSunriseSunset() {
Location lastKnownLocation = osmandApplication.getLocationProvider().getLastKnownLocation();
if (lastKnownLocation == null) {
lastKnownLocation = osmandApplication.getLocationProvider().getFirstTimeRunDefaultLocation();
}
if (lastKnownLocation == null) {
return null;
}
double longitude = lastKnownLocation.getLongitude();
Date actualTime = new Date();
SunriseSunset daynightSwitch = new SunriseSunset(lastKnownLocation.getLatitude(), longitude < 0 ? 360 + longitude : longitude, actualTime, TimeZone.getDefault());
return daynightSwitch;
}
Aggregations