Search in sources :

Example 11 with LatLon

use of net.osmand.data.LatLon in project OsmAnd-tools by osmandapp.

the class IndexAddressCreator method indexAddressRelation.

public void indexAddressRelation(Relation i, OsmDbAccessorContext ctx) throws SQLException {
    if ("street".equals(i.getTag(OSMTagKey.TYPE)) || "associatedStreet".equals(i.getTag(OSMTagKey.TYPE))) {
        // $NON-NLS-1$
        LatLon l = null;
        String streetName = null;
        Set<String> isInNames = null;
        ctx.loadEntityRelation(i);
        streetName = i.getTag(OSMTagKey.NAME);
        Iterator<Entity> it = i.getMemberEntities(null).iterator();
        while (l == null && it.hasNext()) {
            // get coordinates from any relation member
            l = it.next().getLatLon();
        }
        isInNames = i.getIsInNames();
        String postcode = i.getTag(OSMTagKey.ADDR_POSTCODE);
        if (streetName == null) {
            // use relation name as a street name
            Collection<Entity> members = i.getMemberEntities("street");
            for (Entity street : members) {
                // find the first street member with name and use it as a street name
                String name = street.getTag(OSMTagKey.NAME);
                if (name != null) {
                    streetName = name;
                    l = street.getLatLon();
                    isInNames = street.getIsInNames();
                    break;
                }
            }
        }
        if (streetName != null) {
            Set<Long> idsOfStreet = getStreetInCity(isInNames, streetName, null, l);
            if (!idsOfStreet.isEmpty()) {
                // both house and address roles can have address
                Collection<Entity> houses = i.getMemberEntities("house");
                houses.addAll(i.getMemberEntities("address"));
                for (Entity house : houses) {
                    String hname = null;
                    String second = null;
                    if (DataExtractionSettings.getSettings().isHousenumberPrefered()) {
                        hname = house.getTag(OSMTagKey.ADDR_HOUSE_NUMBER);
                        second = house.getTag(OSMTagKey.ADDR_HOUSE_NAME);
                    } else {
                        hname = house.getTag(OSMTagKey.ADDR_HOUSE_NAME);
                        second = house.getTag(OSMTagKey.ADDR_HOUSE_NUMBER);
                    }
                    if (hname == null) {
                        hname = second;
                        second = null;
                    }
                    if (hname == null)
                        continue;
                    if (DataExtractionSettings.getSettings().isAdditionalInfo() && second != null)
                        hname += " - [" + second + "]";
                    if (!streetDAO.findBuilding(house)) {
                        // process multipolygon (relation) houses - preload members to create building with correct latlon
                        if (house instanceof Relation)
                            ctx.loadEntityRelation((Relation) house);
                        Building building = EntityParser.parseBuilding(house);
                        if (building.getLocation() == null) {
                            log.warn("building with empty location! id: " + house.getId());
                        } else {
                            building.setName(hname);
                            if (Algorithms.isEmpty(building.getPostcode())) {
                                building.setPostcode(postcode);
                            }
                            streetDAO.writeBuilding(idsOfStreet, building);
                        }
                    }
                }
            }
        }
    }
}
Also used : Building(net.osmand.data.Building) LatLon(net.osmand.data.LatLon) Entity(net.osmand.osm.edit.Entity) Relation(net.osmand.osm.edit.Relation)

Example 12 with LatLon

use of net.osmand.data.LatLon in project OsmAnd-tools by osmandapp.

the class AugmentedDiffsInspector method registerNewNode.

private Node registerNewNode(XmlPullParser parser, Context ctx, boolean old, EntityId oid) {
    Node nd = null;
    if (oid != null) {
        nd = (Node) (old ? ctx.oldOIds.get(oid) : ctx.newOIds.get(oid));
        if (nd != null) {
            return nd;
        }
    }
    double lat = Double.parseDouble(parser.getAttributeValue("", "lat"));
    double lon = Double.parseDouble(parser.getAttributeValue("", "lon"));
    LatLon ll = new LatLon(lat, lon);
    nd = old ? ctx.oldLocNodes.get(ll) : ctx.newLocNodes.get(ll);
    if (nd == null) {
        nd = new Node(lat, lon, ID_BASE--);
        if (oid != null) {
            nd.putTag("oid", oid.getId().toString());
        }
        registerEntity(ctx, old, nd);
        if (old) {
            ctx.oldLocNodes.put(ll, nd);
        } else {
            ctx.newLocNodes.put(ll, nd);
        }
    }
    registerByOldId(ctx, old, nd, oid);
    return nd;
}
Also used : LatLon(net.osmand.data.LatLon) Node(net.osmand.osm.edit.Node)

Example 13 with LatLon

use of net.osmand.data.LatLon in project Osmand by osmandapp.

the class DashRecentsFragment method setupRecents.

public void setupRecents() {
    View mainView = getView();
    SearchHistoryHelper helper = SearchHistoryHelper.getInstance((OsmandApplication) getActivity().getApplicationContext());
    points = helper.getHistoryEntries();
    arrows.clear();
    if (points.size() == 0) {
        (mainView.findViewById(R.id.main_fav)).setVisibility(View.GONE);
        return;
    } else {
        (mainView.findViewById(R.id.main_fav)).setVisibility(View.VISIBLE);
    }
    LinearLayout recents = (LinearLayout) mainView.findViewById(R.id.items);
    recents.removeAllViews();
    DashboardOnMap.handleNumberOfRows(points, getMyApplication().getSettings(), ROW_NUMBER_TAG);
    LatLon loc = getDefaultLocation();
    List<DashLocationView> distances = new ArrayList<DashLocationFragment.DashLocationView>();
    for (final HistoryEntry historyEntry : points) {
        LayoutInflater inflater = getActivity().getLayoutInflater();
        View view = inflater.inflate(R.layout.search_history_list_item, null, false);
        SearchHistoryFragment.udpateHistoryItem(historyEntry, view, loc, getActivity(), getMyApplication());
        view.findViewById(R.id.divider).setVisibility(View.VISIBLE);
        view.findViewById(R.id.navigate_to).setVisibility(View.VISIBLE);
        ((ImageView) view.findViewById(R.id.navigate_to)).setImageDrawable(getMyApplication().getIconsCache().getThemedIcon(R.drawable.ic_action_gdirections_dark));
        view.findViewById(R.id.navigate_to).setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                DirectionsDialogs.directionsToDialogAndLaunchMap(getActivity(), historyEntry.getLat(), historyEntry.getLon(), historyEntry.getName());
            }
        });
        view.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                getMyApplication().getSettings().setMapLocationToShow(historyEntry.getLat(), historyEntry.getLon(), 15, historyEntry.getName(), true, // $NON-NLS-1$
                historyEntry);
                MapActivity.launchMapActivityMoveToTop(getActivity());
            }
        });
        DashLocationView dv = new DashLocationView((ImageView) view.findViewById(R.id.direction), (TextView) view.findViewById(R.id.distance), new LatLon(historyEntry.getLat(), historyEntry.getLon()));
        distances.add(dv);
        recents.addView(view);
    }
    this.distances = distances;
}
Also used : ArrayList(java.util.ArrayList) ImageView(android.widget.ImageView) TextView(android.widget.TextView) View(android.view.View) LatLon(net.osmand.data.LatLon) SearchHistoryHelper(net.osmand.plus.helpers.SearchHistoryHelper) LayoutInflater(android.view.LayoutInflater) HistoryEntry(net.osmand.plus.helpers.SearchHistoryHelper.HistoryEntry) ImageView(android.widget.ImageView) LinearLayout(android.widget.LinearLayout)

Example 14 with LatLon

use of net.osmand.data.LatLon in project Osmand by osmandapp.

the class DirectionsDialogs method addWaypointDialogAndLaunchMap.

public static void addWaypointDialogAndLaunchMap(final AppCompatActivity act, final double lat, final double lon, final PointDescription name) {
    final TargetPointsHelper targetPointsHelper = ((OsmandApplication) act.getApplication()).getTargetPointsHelper();
    if (targetPointsHelper.getPointToNavigate() != null) {
        Bundle args = new Bundle();
        args.putDouble(AddWaypointBottomSheetDialogFragment.LAT_KEY, lat);
        args.putDouble(AddWaypointBottomSheetDialogFragment.LON_KEY, lon);
        args.putString(AddWaypointBottomSheetDialogFragment.POINT_DESCRIPTION_KEY, PointDescription.serializeToString(name));
        AddWaypointBottomSheetDialogFragment fragment = new AddWaypointBottomSheetDialogFragment();
        fragment.setArguments(args);
        fragment.show(act.getSupportFragmentManager(), AddWaypointBottomSheetDialogFragment.TAG);
    } else {
        targetPointsHelper.navigateToPoint(new LatLon(lat, lon), true, -1, name);
        closeContextMenu(act);
        MapActivity.launchMapActivityMoveToTop(act);
    }
}
Also used : LatLon(net.osmand.data.LatLon) OsmandApplication(net.osmand.plus.OsmandApplication) Bundle(android.os.Bundle) TargetPointsHelper(net.osmand.plus.TargetPointsHelper)

Example 15 with LatLon

use of net.osmand.data.LatLon in project Osmand by osmandapp.

the class RoutingHelper method updateCurrentRouteStatus.

private boolean updateCurrentRouteStatus(Location currentLocation, float posTolerance) {
    List<Location> routeNodes = route.getImmutableAllLocations();
    int currentRoute = route.currentRoute;
    // 1. Try to proceed to next point using orthogonal distance (finding minimum orthogonal dist)
    while (currentRoute + 1 < routeNodes.size()) {
        double dist = currentLocation.distanceTo(routeNodes.get(currentRoute));
        if (currentRoute > 0) {
            dist = getOrthogonalDistance(currentLocation, routeNodes.get(currentRoute - 1), routeNodes.get(currentRoute));
        }
        boolean processed = false;
        // if we are still too far try to proceed many points
        // if not then look ahead only 3 in order to catch sharp turns
        boolean longDistance = dist >= 250;
        int newCurrentRoute = lookAheadFindMinOrthogonalDistance(currentLocation, routeNodes, currentRoute, longDistance ? 15 : 8);
        double newDist = getOrthogonalDistance(currentLocation, routeNodes.get(newCurrentRoute), routeNodes.get(newCurrentRoute + 1));
        if (longDistance) {
            if (newDist < dist) {
                if (log.isDebugEnabled()) {
                    // $NON-NLS-1$//$NON-NLS-2$
                    log.debug("Processed by distance : (new) " + newDist + " (old) " + dist);
                }
                processed = true;
            }
        } else if (newDist < dist || newDist < 10) {
            // newDist < 10 (avoid distance 0 till next turn)
            if (dist > posTolerance) {
                processed = true;
                if (log.isDebugEnabled()) {
                    // $NON-NLS-1$//$NON-NLS-2$
                    log.debug("Processed by distance : " + newDist + " " + dist);
                }
            } else {
                // but you have not yet turned (could be checked bearing)
                if (currentLocation.hasBearing() || lastFixedLocation != null) {
                    float bearingToRoute = currentLocation.bearingTo(routeNodes.get(currentRoute));
                    float bearingRouteNext = routeNodes.get(newCurrentRoute).bearingTo(routeNodes.get(newCurrentRoute + 1));
                    float bearingMotion = currentLocation.hasBearing() ? currentLocation.getBearing() : lastFixedLocation.bearingTo(currentLocation);
                    double diff = Math.abs(MapUtils.degreesDiff(bearingMotion, bearingToRoute));
                    double diffToNext = Math.abs(MapUtils.degreesDiff(bearingMotion, bearingRouteNext));
                    if (diff > diffToNext) {
                        if (log.isDebugEnabled()) {
                            log.debug("Processed point bearing deltas : " + diff + " " + diffToNext);
                        }
                        processed = true;
                    }
                }
            }
        }
        if (processed) {
            // that node already passed
            route.updateCurrentRoute(newCurrentRoute + 1);
            currentRoute = newCurrentRoute + 1;
            app.getNotificationHelper().refreshNotification(NotificationType.NAVIGATION);
        } else {
            break;
        }
    }
    // 2. check if intermediate found
    if (route.getIntermediatePointsToPass() > 0 && route.getDistanceToNextIntermediate(lastFixedLocation) < getArrivalDistance() * 2f && !isRoutePlanningMode) {
        showMessage(app.getString(R.string.arrived_at_intermediate_point));
        route.passIntermediatePoint();
        TargetPointsHelper targets = app.getTargetPointsHelper();
        String name = "";
        if (intermediatePoints != null && !intermediatePoints.isEmpty()) {
            LatLon rm = intermediatePoints.remove(0);
            List<TargetPoint> ll = targets.getIntermediatePointsNavigation();
            int ind = -1;
            for (int i = 0; i < ll.size(); i++) {
                if (ll.get(i).point != null && MapUtils.getDistance(ll.get(i).point, rm) < 5) {
                    name = ll.get(i).getOnlyName();
                    ind = i;
                    break;
                }
            }
            if (ind >= 0) {
                targets.removeWayPoint(false, ind);
            }
        }
        if (isFollowingMode) {
            voiceRouter.arrivedIntermediatePoint(name);
        }
        // double check
        while (intermediatePoints != null && route.getIntermediatePointsToPass() < intermediatePoints.size()) {
            intermediatePoints.remove(0);
        }
    }
    // 3. check if destination found
    Location lastPoint = routeNodes.get(routeNodes.size() - 1);
    if (currentRoute > routeNodes.size() - 3 && currentLocation.distanceTo(lastPoint) < getArrivalDistance() && !isRoutePlanningMode) {
        // showMessage(app.getString(R.string.arrived_at_destination));
        TargetPointsHelper targets = app.getTargetPointsHelper();
        TargetPoint tp = targets.getPointToNavigate();
        String description = tp == null ? "" : tp.getOnlyName();
        if (isFollowingMode) {
            voiceRouter.arrivedDestinationPoint(description);
        }
        boolean onDestinationReached = OsmandPlugin.onDestinationReached();
        onDestinationReached &= app.getAppCustomization().onDestinationReached();
        if (onDestinationReached) {
            clearCurrentRoute(null, null);
            setRoutePlanningMode(false);
            app.runInUIThread(new Runnable() {

                @Override
                public void run() {
                    settings.LAST_ROUTING_APPLICATION_MODE = settings.APPLICATION_MODE.get();
                // settings.APPLICATION_MODE.set(settings.DEFAULT_APPLICATION_MODE.get());
                }
            });
            finishCurrentRoute();
            // targets.clearPointToNavigate(false);
            return true;
        }
    }
    return false;
}
Also used : LatLon(net.osmand.data.LatLon) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) TargetPointsHelper(net.osmand.plus.TargetPointsHelper) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) Location(net.osmand.Location)

Aggregations

LatLon (net.osmand.data.LatLon)305 ArrayList (java.util.ArrayList)56 PointDescription (net.osmand.data.PointDescription)44 View (android.view.View)41 Location (net.osmand.Location)38 TextView (android.widget.TextView)32 ImageView (android.widget.ImageView)29 TargetPoint (net.osmand.plus.TargetPointsHelper.TargetPoint)26 OsmandApplication (net.osmand.plus.OsmandApplication)25 Paint (android.graphics.Paint)23 FavouritePoint (net.osmand.data.FavouritePoint)21 RotatedTileBox (net.osmand.data.RotatedTileBox)21 WptPt (net.osmand.plus.GPXUtilities.WptPt)21 MapMarker (net.osmand.plus.MapMarkersHelper.MapMarker)20 TargetPointsHelper (net.osmand.plus.TargetPointsHelper)18 Amenity (net.osmand.data.Amenity)17 OsmandSettings (net.osmand.plus.OsmandSettings)17 Intent (android.content.Intent)16 QuadPoint (net.osmand.data.QuadPoint)13 QuadRect (net.osmand.data.QuadRect)13