Search in sources :

Example 41 with GeoCoordinate

use of com.here.android.mpa.common.GeoCoordinate in project here-android-sdk-examples by heremaps.

the class BasicVenueActivity method updateLocationInfo.

/**
 * Update location information to the log and location view.
 * @param geoPosition Latest geo position update.
 */
private void updateLocationInfo(PositioningManager.LocationMethod locationMethod, GeoPosition geoPosition) {
    if (mLocationInfo == null) {
        return;
    }
    final StringBuffer sb = new StringBuffer();
    final GeoCoordinate coord = geoPosition.getCoordinate();
    if (geoPosition.getPositionSource() != GeoPosition.UNKNOWN) {
        sb.append("Position Source: ").append(String.format(Locale.US, "%s\n", positionSourceToString(geoPosition)));
    }
    if (geoPosition.getPositionTechnology() != GeoPosition.UNKNOWN) {
        sb.append("Position Technology: ").append(String.format(Locale.US, "%s\n", positionTechnologyToString(geoPosition)));
    }
    sb.append("Coordinate:").append(String.format(Locale.US, "%.6f, %.6f\n", coord.getLatitude(), coord.getLongitude()));
    if (geoPosition.getLatitudeAccuracy() != GeoPosition.UNKNOWN) {
        sb.append("Uncertainty:").append(String.format(Locale.US, "%.2fm\n", geoPosition.getLatitudeAccuracy()));
    }
    if (coord.getAltitude() != GeoCoordinate.UNKNOWN_ALTITUDE) {
        sb.append("Altitude:").append(String.format(Locale.US, "%.2fm\n", coord.getAltitude()));
    }
    if (geoPosition.getHeading() != GeoPosition.UNKNOWN) {
        sb.append("Heading:").append(String.format(Locale.US, "%.2f\n", geoPosition.getHeading()));
    }
    if (geoPosition.getSpeed() != GeoPosition.UNKNOWN) {
        sb.append("Speed:").append(String.format(Locale.US, "%.2fm/s\n", geoPosition.getSpeed()));
    }
    if (geoPosition.getBuildingName() != null) {
        sb.append("Building: ").append(geoPosition.getBuildingName());
        if (geoPosition.getBuildingId() != null) {
            sb.append(" (").append(geoPosition.getBuildingId()).append(")\n");
        } else {
            sb.append("\n");
        }
    }
    if (geoPosition.getFloorId() != null) {
        sb.append("Floor ID: ").append(geoPosition.getFloorId()).append("\n");
    }
    sb.deleteCharAt(sb.length() - 1);
    mLocationInfo.setText(sb.toString());
    Log.v(TAG, "Position Updated:\n%s", sb.toString());
}
Also used : GeoCoordinate(com.here.android.mpa.common.GeoCoordinate)

Example 42 with GeoCoordinate

use of com.here.android.mpa.common.GeoCoordinate in project here-android-sdk-examples by heremaps.

the class BasicVenueActivity method onPositionUpdated.

@Override
public void onPositionUpdated(final PositioningManager.LocationMethod locationMethod, final GeoPosition geoPosition, final boolean mapMatched) {
    mLastReceivedPosition = geoPosition;
    GeoCoordinate receivedCoordinate = mLastReceivedPosition.getCoordinate();
    if (mTransforming) {
        mPendingUpdate = new Runnable() {

            @Override
            public void run() {
                onPositionUpdated(locationMethod, geoPosition, mapMatched);
            }
        };
    } else {
        if (mVenueMapFragment != null) {
            mLastMapCenter = receivedCoordinate;
            if (!mUserControl) {
                // when "follow position" options selected than map centered according to position updates
                mMap.setCenter(receivedCoordinate, Map.Animation.NONE);
                // Correctly displaying indoor position inside the venue
                if (geoPosition.getPositionSource() == GeoPosition.SOURCE_INDOOR) {
                    if (!geoPosition.getBuildingId().isEmpty() && mPrivateVenues) {
                        mVenueMapFragment.selectVenueAsync(geoPosition.getBuildingId());
                        mVenueMapFragment.getVenueController(mVenueMapFragment.getSelectedVenue());
                        selectLevelByFloorId(geoPosition.getFloorId());
                    }
                }
            }
        }
        // Write updated position to the log and to info view
        updateLocationInfo(locationMethod, geoPosition);
    }
}
Also used : GeoCoordinate(com.here.android.mpa.common.GeoCoordinate)

Example 43 with GeoCoordinate

use of com.here.android.mpa.common.GeoCoordinate in project here-android-sdk-examples by heremaps.

the class BasicPositioningActivity method updateLocationInfo.

/**
 * Update location information.
 * @param geoPosition Latest geo position update.
 */
private void updateLocationInfo(PositioningManager.LocationMethod locationMethod, GeoPosition geoPosition) {
    if (mLocationInfo == null) {
        return;
    }
    final StringBuffer sb = new StringBuffer();
    final GeoCoordinate coord = geoPosition.getCoordinate();
    sb.append("Type: ").append(String.format(Locale.US, "%s\n", locationMethod.name()));
    sb.append("Coordinate:").append(String.format(Locale.US, "%.6f, %.6f\n", coord.getLatitude(), coord.getLongitude()));
    if (coord.getAltitude() != GeoCoordinate.UNKNOWN_ALTITUDE) {
        sb.append("Altitude:").append(String.format(Locale.US, "%.2fm\n", coord.getAltitude()));
    }
    if (geoPosition.getHeading() != GeoPosition.UNKNOWN) {
        sb.append("Heading:").append(String.format(Locale.US, "%.2f\n", geoPosition.getHeading()));
    }
    if (geoPosition.getSpeed() != GeoPosition.UNKNOWN) {
        sb.append("Speed:").append(String.format(Locale.US, "%.2fm/s\n", geoPosition.getSpeed()));
    }
    if (geoPosition.getBuildingName() != null) {
        sb.append("Building: ").append(geoPosition.getBuildingName());
        if (geoPosition.getBuildingId() != null) {
            sb.append(" (").append(geoPosition.getBuildingId()).append(")\n");
        } else {
            sb.append("\n");
        }
    }
    if (geoPosition.getFloorId() != null) {
        sb.append("Floor: ").append(geoPosition.getFloorId()).append("\n");
    }
    sb.deleteCharAt(sb.length() - 1);
    mLocationInfo.setText(sb.toString());
}
Also used : GeoCoordinate(com.here.android.mpa.common.GeoCoordinate)

Example 44 with GeoCoordinate

use of com.here.android.mpa.common.GeoCoordinate in project here-android-sdk-examples by heremaps.

the class BasicPositioningActivity method onPositionUpdated.

@Override
public void onPositionUpdated(final PositioningManager.LocationMethod locationMethod, final GeoPosition geoPosition, final boolean mapMatched) {
    final GeoCoordinate coordinate = geoPosition.getCoordinate();
    if (mTransforming) {
        mPendingUpdate = new Runnable() {

            @Override
            public void run() {
                onPositionUpdated(locationMethod, geoPosition, mapMatched);
            }
        };
    } else {
        map.setCenter(coordinate, Map.Animation.BOW);
        updateLocationInfo(locationMethod, geoPosition);
    }
}
Also used : GeoCoordinate(com.here.android.mpa.common.GeoCoordinate)

Example 45 with GeoCoordinate

use of com.here.android.mpa.common.GeoCoordinate in project here-android-sdk-examples by heremaps.

the class MapFragmentView method createRoute.

private void createRoute(final List<RoutingZone> excludedRoutingZones) {
    /* Initialize a CoreRouter */
    CoreRouter coreRouter = new CoreRouter();
    /* Initialize a RoutePlan */
    RoutePlan routePlan = new RoutePlan();
    /*
         * Initialize a RouteOption. HERE Mobile SDK allow users to define their own parameters for the
         * route calculation,including transport modes,route types and route restrictions etc.Please
         * refer to API doc for full list of APIs
         */
    RouteOptions routeOptions = new RouteOptions();
    /* Other transport modes are also available e.g Pedestrian */
    routeOptions.setTransportMode(RouteOptions.TransportMode.CAR);
    /* Disable highway in this route. */
    routeOptions.setHighwaysAllowed(false);
    /* Calculate the shortest route available. */
    routeOptions.setRouteType(RouteOptions.Type.SHORTEST);
    /* Calculate 1 route. */
    routeOptions.setRouteCount(1);
    /* Exclude routing zones. */
    if (!excludedRoutingZones.isEmpty()) {
        routeOptions.excludeRoutingZones(toStringIds(excludedRoutingZones));
    }
    if (m_addAvoidedAreas) {
        DynamicPenalty dynamicPenalty = new DynamicPenalty();
        // There are two option to avoid certain areas during routing
        // 1. Add banned area using addBannedArea API
        GeoPolygon geoPolygon = new GeoPolygon();
        geoPolygon.add(Arrays.asList(new GeoCoordinate(52.631692, 13.437591), new GeoCoordinate(52.631905, 13.437787), new GeoCoordinate(52.632577, 13.438357)));
        // Note, the maximum supported number of banned areas is 20.
        dynamicPenalty.addBannedArea(geoPolygon);
        // 1. Add banned road link using addRoadPenalty API
        // Note, map data needs to be present to get RoadElement by the GeoCoordinate.
        RoadElement roadElement = RoadElement.getRoadElement(new GeoCoordinate(52.406611, 13.194916), "MAC");
        if (roadElement != null) {
            dynamicPenalty.addRoadPenalty(roadElement, DrivingDirection.DIR_BOTH, 0);
        }
        coreRouter.setDynamicPenalty(dynamicPenalty);
    }
    /* Finally set the route option */
    routePlan.setRouteOptions(routeOptions);
    /* Define waypoints for the route */
    /* START: South of Berlin */
    RouteWaypoint startPoint = new RouteWaypoint(new GeoCoordinate(52.406425, 13.193975));
    /* END: North of Berlin */
    RouteWaypoint destination = new RouteWaypoint(new GeoCoordinate(52.638623, 13.441998));
    /* Add both waypoints to the route plan */
    routePlan.addWaypoint(startPoint);
    routePlan.addWaypoint(destination);
    /* Trigger the route calculation,results will be called back via the listener */
    coreRouter.calculateRoute(routePlan, new Router.Listener<List<RouteResult>, RoutingError>() {

        @Override
        public void onProgress(int i) {
        /* The calculation progress can be retrieved in this callback. */
        }

        @Override
        public void onCalculateRouteFinished(List<RouteResult> routeResults, RoutingError routingError) {
            /* Calculation is done. Let's handle the result */
            if (routingError == RoutingError.NONE) {
                Route route = routeResults.get(0).getRoute();
                if (m_isExcludeRoutingZones && excludedRoutingZones.isEmpty()) {
                    // Here we exclude all available routing zones in the route.
                    // Also RoutingZoneRestrictionsChecker can be used to get
                    // available routing zones for specific RoadElement.
                    createRoute(route.getRoutingZones());
                } else {
                    /* Create a MapRoute so that it can be placed on the map */
                    m_mapRoute = new MapRoute(route);
                    /* Show the maneuver number on top of the route */
                    m_mapRoute.setManeuverNumberVisible(true);
                    /* Add the MapRoute to the map */
                    m_map.addMapObject(m_mapRoute);
                    /*
                                 * We may also want to make sure the map view is orientated properly
                                 * so the entire route can be easily seen.
                                 */
                    m_map.zoomTo(route.getBoundingBox(), Map.Animation.NONE, Map.MOVE_PRESERVE_ORIENTATION);
                }
            } else {
                Toast.makeText(m_activity, "Error:route calculation returned error code: " + routingError, Toast.LENGTH_LONG).show();
            }
        }
    });
}
Also used : MapRoute(com.here.android.mpa.mapping.MapRoute) RoadElement(com.here.android.mpa.common.RoadElement) CoreRouter(com.here.android.mpa.routing.CoreRouter) Router(com.here.android.mpa.routing.Router) CoreRouter(com.here.android.mpa.routing.CoreRouter) GeoCoordinate(com.here.android.mpa.common.GeoCoordinate) RouteOptions(com.here.android.mpa.routing.RouteOptions) RouteWaypoint(com.here.android.mpa.routing.RouteWaypoint) DynamicPenalty(com.here.android.mpa.routing.DynamicPenalty) GeoPolygon(com.here.android.mpa.common.GeoPolygon) RouteWaypoint(com.here.android.mpa.routing.RouteWaypoint) RoutingError(com.here.android.mpa.routing.RoutingError) RouteResult(com.here.android.mpa.routing.RouteResult) ArrayList(java.util.ArrayList) List(java.util.List) RoutePlan(com.here.android.mpa.routing.RoutePlan) Route(com.here.android.mpa.routing.Route) MapRoute(com.here.android.mpa.mapping.MapRoute)

Aggregations

GeoCoordinate (com.here.android.mpa.common.GeoCoordinate)50 OnEngineInitListener (com.here.android.mpa.common.OnEngineInitListener)17 DialogInterface (android.content.DialogInterface)12 RouteWaypoint (com.here.android.mpa.routing.RouteWaypoint)11 File (java.io.File)10 GeoBoundingBox (com.here.android.mpa.common.GeoBoundingBox)9 ArrayList (java.util.ArrayList)9 MapMarker (com.here.android.mpa.mapping.MapMarker)7 CoreRouter (com.here.android.mpa.routing.CoreRouter)7 List (java.util.List)7 MapRoute (com.here.android.mpa.mapping.MapRoute)6 RoutePlan (com.here.android.mpa.routing.RoutePlan)6 RouteOptions (com.here.android.mpa.routing.RouteOptions)5 RouteResult (com.here.android.mpa.routing.RouteResult)5 RoutingError (com.here.android.mpa.routing.RoutingError)5 ApplicationInfo (android.content.pm.ApplicationInfo)4 PackageManager (android.content.pm.PackageManager)4 Bundle (android.os.Bundle)4 GeoPolyline (com.here.android.mpa.common.GeoPolyline)4 Image (com.here.android.mpa.common.Image)4