Search in sources :

Example 6 with GeoCoordinate

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

the class MapFragmentView method makeRequest.

void makeRequest(GeoCoordinate[] list, final Callback callback) {
    final HttpRequest httpRequest = HttpRequest.post(URL_UPLOAD_ROUTE + "?app_id=" + m_appId + "&app_code=" + m_appToken + "&map_name=" + m_overlayName + "&storage=readonly");
    final StringBuilder overlaySpec = new StringBuilder();
    overlaySpec.append("[");
    StringBuilder pathStr = new StringBuilder();
    pathStr.append("[");
    for (GeoCoordinate geoCoordinate : list) {
        pathStr.append("[").append(geoCoordinate.getLatitude()).append(",").append(geoCoordinate.getLongitude()).append("]").append(",");
    }
    pathStr.deleteCharAt(pathStr.length() - 1);
    pathStr.append("]");
    String shape = "{\"op\":\"create\",\"shape\":" + pathStr + "}";
    overlaySpec.append(shape).append(",");
    overlaySpec.deleteCharAt(overlaySpec.length() - 1);
    overlaySpec.append("]");
    new Thread(new Runnable() {

        @Override
        public void run() {
            if (MapFragmentView.this.m_activity.isDestroyed()) {
                return;
            }
            httpRequest.part("overlay_spec", overlaySpec.toString());
            if (httpRequest.created()) {
                callback.onResponse(httpRequest.body());
            } else {
                String message;
                try {
                    message = "Code:" + httpRequest.code() + ", " + httpRequest.body();
                } catch (HttpRequest.HttpRequestException e) {
                    message = e.getMessage();
                }
                callback.onResponse(message);
            }
        }
    }).start();
}
Also used : HttpRequest(com.github.kevinsawicki.http.HttpRequest) GeoCoordinate(com.here.android.mpa.common.GeoCoordinate)

Example 7 with GeoCoordinate

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

the class Venue3dActivity method onTapEvent.

@SuppressLint("DefaultLocale")
@Override
public boolean onTapEvent(PointF p) {
    if (!m_is_routing_mode) {
        return false;
    }
    GeoCoordinate touchLocation = m_map.pixelToGeo(p);
    double lat = touchLocation.getLatitude();
    double lon = touchLocation.getLongitude();
    String StrGeo = String.format("%.6f, %.6f", lat, lon);
    Toast.makeText(getApplicationContext(), StrGeo, Toast.LENGTH_SHORT).show();
    addToRoute(new OutdoorLocation(touchLocation), StrGeo);
    return false;
}
Also used : GeoCoordinate(com.here.android.mpa.common.GeoCoordinate) OutdoorLocation(com.here.android.mpa.venues3d.OutdoorLocation) SuppressLint(android.annotation.SuppressLint)

Example 8 with GeoCoordinate

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

the class MapFragmentView method calculateAndStartNavigation.

private void calculateAndStartNavigation() {
    if (m_map == null) {
        Toast.makeText(m_activity, "Map is not ready yet", Toast.LENGTH_SHORT).show();
        return;
    }
    if (NavigationManager.getInstance().getRunningState() == NavigationManager.NavigationState.RUNNING) {
        Toast.makeText(m_activity, "Navigation is currently running", Toast.LENGTH_SHORT).show();
        return;
    }
    final RoutePlan routePlan = new RoutePlan();
    // these two waypoints cover suburban roads
    routePlan.addWaypoint(new RouteWaypoint(new GeoCoordinate(48.960497, 2.47351)));
    routePlan.addWaypoint(new RouteWaypoint(new GeoCoordinate(48.976, 2.49162)));
    // calculate a route for navigation
    CoreRouter coreRouter = new CoreRouter();
    coreRouter.calculateRoute(routePlan, new CoreRouter.Listener() {

        @Override
        public void onCalculateRouteFinished(List<RouteResult> list, RoutingError routingError) {
            if (routingError == RoutingError.NONE) {
                Route route = list.get(0).getRoute();
                m_currentRoute = new MapRoute(route);
                m_map.addMapObject(m_currentRoute);
                // move the map to the first waypoint which is starting point of
                // the route
                m_map.setCenter(routePlan.getWaypoint(0).getNavigablePosition(), Map.Animation.NONE);
                // setting MapUpdateMode to RoadView will enable automatic map
                // movements and zoom level adjustments
                NavigationManager navigationManager = NavigationManager.getInstance();
                navigationManager.setMapUpdateMode(NavigationManager.MapUpdateMode.ROADVIEW);
                // adjust tilt to show 3D view
                m_map.setTilt(80);
                // adjust transform center for navigation experience in portrait
                // view
                m_mapTransformCenter = new PointF(m_map.getTransformCenter().x, (m_map.getTransformCenter().y * 85 / 50));
                m_map.setTransformCenter(m_mapTransformCenter);
                // create a map marker to show current position
                Image icon = new Image();
                m_positionIndicatorFixed = new MapMarker();
                try {
                    icon.setImageResource(R.drawable.gps_position);
                    m_positionIndicatorFixed.setIcon(icon);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                m_positionIndicatorFixed.setVisible(true);
                m_positionIndicatorFixed.setCoordinate(m_map.getCenter());
                m_map.addMapObject(m_positionIndicatorFixed);
                m_mapFragment.getPositionIndicator().setVisible(false);
                navigationManager.setMap(m_map);
                // listen to real position updates. This is used when RoadView is
                // not active.
                PositioningManager.getInstance().addListener(new WeakReference<>(mapPositionHandler));
                // listen to updates from RoadView which tells you where the map
                // center should be situated. This is used when RoadView is active.
                navigationManager.getRoadView().addListener(new WeakReference<>(roadViewListener));
                // listen to navigation manager events.
                navigationManager.addNavigationManagerEventListener(new WeakReference<>(navigationManagerEventListener));
                navigationManager.addLaneInformationListener(new WeakReference<>(m_laneInformationListener));
                // start navigation simulation travelling at 13 meters per second
                navigationManager.simulate(route, 13);
            } else {
                Toast.makeText(m_activity, "Error:route calculation returned error code: " + routingError, Toast.LENGTH_LONG).show();
            }
        }

        @Override
        public void onProgress(int i) {
        }
    });
}
Also used : MapRoute(com.here.android.mpa.mapping.MapRoute) NavigationManager(com.here.android.mpa.guidance.NavigationManager) MapMarker(com.here.android.mpa.mapping.MapMarker) PointF(android.graphics.PointF) CoreRouter(com.here.android.mpa.routing.CoreRouter) GeoCoordinate(com.here.android.mpa.common.GeoCoordinate) IOException(java.io.IOException) RouteWaypoint(com.here.android.mpa.routing.RouteWaypoint) Image(com.here.android.mpa.common.Image) RouteWaypoint(com.here.android.mpa.routing.RouteWaypoint) RoutingError(com.here.android.mpa.routing.RoutingError) RouteResult(com.here.android.mpa.routing.RouteResult) WeakReference(java.lang.ref.WeakReference) RoutePlan(com.here.android.mpa.routing.RoutePlan) Route(com.here.android.mpa.routing.Route) MapRoute(com.here.android.mpa.mapping.MapRoute)

Example 9 with GeoCoordinate

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

the class MapFragmentView method showRoute.

private void showRoute() {
    m_startNavPoint = new GeoCoordinate(55.93176, -3.22734);
    m_endNavPoint = new GeoCoordinate(55.98084, -3.17778);
    calculateRoute(m_startNavPoint, m_endNavPoint);
    List<GeoCoordinate> geoCoordinateList = new ArrayList<>();
    geoCoordinateList.add(m_startNavPoint);
    geoCoordinateList.add(m_endNavPoint);
    m_geoBoundingBox = GeoBoundingBox.getBoundingBoxContainingGeoCoordinates(geoCoordinateList);
    m_map.zoomTo(m_geoBoundingBox, m_map.getWidth() - ZOOM_WIDTH, m_map.getHeight() - ZOOM_HEIGHT, Map.Animation.NONE, 0);
    changeState(State.PREFETCH_MAP);
}
Also used : ArrayList(java.util.ArrayList) GeoCoordinate(com.here.android.mpa.common.GeoCoordinate)

Example 10 with GeoCoordinate

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

the class MapFragmentView method roadSlopes.

/**
 * Method contains logic for extracting data about slopes and showing it on a route
 */
private void roadSlopes() {
    final java.util.Map<String, Integer> slopesMap = new HashMap<>();
    final java.util.Map<String, List<GeoCoordinate>> geometryMap = new HashMap<>();
    /*
         * Create a route plan for route calculation
         */
    RoutePlan rp = new RoutePlan();
    rp.addWaypoint(new RouteWaypoint(new GeoCoordinate(37.79513, -122.47603)));
    rp.addWaypoint(new RouteWaypoint(new GeoCoordinate(37.78166, -122.44450)));
    CoreRouter router = new CoreRouter();
    /*
         * For getting list of Link IDs routing should be forced to work online
         */
    router.setConnectivity(CoreRouter.Connectivity.ONLINE);
    router.calculateRoute(rp, new CoreRouter.Listener() {

        @Override
        public void onCalculateRouteFinished(List<RouteResult> list, RoutingError routingError) {
            if (routingError == RoutingError.NONE) {
                Route route = list.get(0).getRoute();
                /*
                     * Show route on the map and zoom to the route
                     */
                GeoBoundingBox bbox = route.getBoundingBox();
                map.addMapObject(new MapRoute(route));
                map.zoomTo(bbox, Map.Animation.NONE, 0);
                /*
                     * Get list of Link IDs for the route
                     */
                final List<Long> ids = route.getPermanentLinkIds();
                for (Long id : ids) {
                    pvids.add(id);
                }
                Set<String> layers = new HashSet<>(Arrays.asList(ADAS_LAYER, ROAD_GEOM_LAYER));
                PlatformDataRequest request = PlatformDataRequest.createBoundingBoxRequest(layers, bbox);
                request.execute(new PlatformDataRequest.Listener<PlatformDataResult>() {

                    @Override
                    public void onCompleted(PlatformDataResult data, PlatformDataRequest.Error error) {
                        if (error == null) {
                            /*
                                 * Process route geometry from PDE
                                 */
                            PlatformDataItemCollection roadDataCollection = data.get(ROAD_GEOM_LAYER);
                            for (PlatformDataItem item : roadDataCollection) {
                                geometryMap.put(item.getLinkId(), item.getCoordinates());
                            }
                            /*
                                 * Process ADAS data from PDE
                                 */
                            PlatformDataItemCollection adasDataCollection = data.get(ADAS_LAYER);
                            for (PlatformDataItem item : adasDataCollection) {
                                List<String> values = new ArrayList<>();
                                /*
                                     * Split slopes data
                                     */
                                StringTokenizer tokenizer = new StringTokenizer(item.get("SLOPES"));
                                while (tokenizer.hasMoreTokens()) {
                                    String token = tokenizer.nextToken(",");
                                    /*
                                         * Filter out invalid data
                                         */
                                    if (!token.equals("NULL") && !token.equals("1000000000")) {
                                        values.add(token);
                                    }
                                }
                                /*
                                     * Mark slopes data if it contains either high or low value
                                     */
                                int max = 0;
                                int min = 0;
                                for (String str : values) {
                                    int temp = Integer.valueOf(str);
                                    if (temp > max)
                                        max = temp;
                                    if (temp < min)
                                        min = temp;
                                }
                                if ((min * -1) > max && min <= -5_000)
                                    slopesMap.put(item.getLinkId(), LOW_COLOR);
                                else if ((min * -1) < max && max >= 5_000)
                                    slopesMap.put(item.getLinkId(), HIGH_COLOR);
                            }
                            /*
                                 * Process list of geometry
                                 * find route segment with high or low slopes value
                                 * and add this geometry to the list
                                 */
                            List<MapObject> polylines = new ArrayList<>();
                            for (java.util.Map.Entry<String, List<GeoCoordinate>> entry : geometryMap.entrySet()) {
                                if (pvids.contains(Long.parseLong(entry.getKey()))) {
                                    GeoPolyline polyline = new GeoPolyline();
                                    polyline.add(entry.getValue());
                                    MapPolyline line = new MapPolyline(polyline);
                                    if (slopesMap.containsKey(entry.getKey())) {
                                        line.setLineColor(slopesMap.get(entry.getKey()));
                                        line.setLineWidth(15);
                                        polylines.add(line);
                                    }
                                }
                            }
                            /*
                                 * Show a list of slopes geometry on the map
                                 */
                            map.addMapObjects(polylines);
                        } else {
                            /*
                                 * Process PDE request error
                                 */
                            Log.i(TAG, "PDE error: " + error.getFaultCode());
                            Log.i(TAG, "PDE error: " + error.getMessage());
                            Log.i(TAG, "PDE error: " + error.getResponseCode());
                            Log.i(TAG, "PDE error: " + error.getType().toString());
                        }
                    }
                });
            } else {
                Log.e(TAG, "Routing error: " + routingError);
            }
        }

        @Override
        public void onProgress(int i) {
            Log.i(TAG, String.format("Route calculation progress: %d%%", i));
        }
    });
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) OnEngineInitListener(com.here.android.mpa.common.OnEngineInitListener) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) PlatformDataItemCollection(com.here.android.mpa.pde.PlatformDataItemCollection) GeoCoordinate(com.here.android.mpa.common.GeoCoordinate) RouteResult(com.here.android.mpa.routing.RouteResult) PlatformDataResult(com.here.android.mpa.pde.PlatformDataResult) ArrayList(java.util.ArrayList) List(java.util.List) RoutePlan(com.here.android.mpa.routing.RoutePlan) MapObject(com.here.android.mpa.mapping.MapObject) Route(com.here.android.mpa.routing.Route) MapRoute(com.here.android.mpa.mapping.MapRoute) PlatformDataItem(com.here.android.mpa.pde.PlatformDataItem) MapRoute(com.here.android.mpa.mapping.MapRoute) CoreRouter(com.here.android.mpa.routing.CoreRouter) RoutingError(com.here.android.mpa.routing.RoutingError) RouteWaypoint(com.here.android.mpa.routing.RouteWaypoint) RouteWaypoint(com.here.android.mpa.routing.RouteWaypoint) StringTokenizer(java.util.StringTokenizer) RoutingError(com.here.android.mpa.routing.RoutingError) PlatformDataRequest(com.here.android.mpa.pde.PlatformDataRequest) MapPolyline(com.here.android.mpa.mapping.MapPolyline) GeoBoundingBox(com.here.android.mpa.common.GeoBoundingBox) HashMap(java.util.HashMap) Map(com.here.android.mpa.mapping.Map) GeoPolyline(com.here.android.mpa.common.GeoPolyline)

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