Search in sources :

Example 31 with GeoCoordinate

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

the class MainView method triggerRevGeocodeRequest.

private void triggerRevGeocodeRequest() {
    m_resultTextView.setText("");
    /* Create a ReverseGeocodeRequest object with a GeoCoordinate. */
    GeoCoordinate coordinate = new GeoCoordinate(49.25914, -123.00777);
    ReverseGeocodeRequest revGecodeRequest = new ReverseGeocodeRequest(coordinate);
    revGecodeRequest.execute(new ResultListener<Location>() {

        @Override
        public void onCompleted(Location location, ErrorCode errorCode) {
            if (errorCode == ErrorCode.NONE) {
                /*
                     * From the location object, we retrieve the address and display to the screen.
                     * Please refer to HERE Android SDK doc for other supported APIs.
                     */
                updateTextView(location.getAddress().toString());
            } else {
                updateTextView("ERROR:RevGeocode Request returned error code:" + errorCode);
            }
        }
    });
}
Also used : GeoCoordinate(com.here.android.mpa.common.GeoCoordinate) ReverseGeocodeRequest(com.here.android.mpa.search.ReverseGeocodeRequest) ErrorCode(com.here.android.mpa.search.ErrorCode) Location(com.here.android.mpa.search.Location)

Example 32 with GeoCoordinate

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

the class MapFragmentView method initMapFragment.

private void initMapFragment() {
    /* Locate the mapFragment UI element */
    m_mapFragment = getMapFragment();
    // This will use external storage to save map cache data, it is also possible to set
    // private app's path
    String path = new File(m_activity.getExternalFilesDir(null), ".here-map-data").getAbsolutePath();
    // This method will throw IllegalArgumentException if provided path is not writable
    com.here.android.mpa.common.MapSettings.setDiskCacheRootPath(path);
    if (m_mapFragment != null) {
        /* Initialize the AndroidXMapFragment, results will be given via the called back. */
        m_mapFragment.init(new OnEngineInitListener() {

            @Override
            public void onEngineInitializationCompleted(OnEngineInitListener.Error error) {
                if (error == Error.NONE) {
                    /*
                     * If no error returned from map fragment initialization, the map will be
                     * rendered on screen at this moment.Further actions on map can be provided
                     * by calling Map APIs.
                     */
                    m_map = m_mapFragment.getMap();
                    /*
                     * Set the map center to the 4350 Still Creek Dr Burnaby BC (no animation).
                     */
                    m_map.setCenter(new GeoCoordinate(49.259149, -123.008555, 0.0), Map.Animation.NONE);
                    /* Set the zoom level to the average between min and max zoom level. */
                    m_map.setZoomLevel(14);
                    m_activity.supportInvalidateOptionsMenu();
                    /*
                      * Set up a handler for handling MapMarker drag events.
                      */
                    m_mapFragment.setMapMarkerDragListener(new OnDragListenerHandler());
                } else {
                    Log.e(this.getClass().toString(), "onEngineInitializationCompleted: " + "ERROR=" + error.getDetails(), error.getThrowable());
                    new AlertDialog.Builder(m_activity).setMessage("Error : " + error.name() + "\n\n" + error.getDetails()).setTitle(R.string.engine_init_error).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            m_activity.finish();
                        }
                    }).create().show();
                }
            }
        });
    }
}
Also used : DialogInterface(android.content.DialogInterface) GeoCoordinate(com.here.android.mpa.common.GeoCoordinate) OnEngineInitListener(com.here.android.mpa.common.OnEngineInitListener) File(java.io.File)

Example 33 with GeoCoordinate

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

the class MapFragmentView method addPolylineObject.

/**
 * Create a MapPolyline and add the MapPolyline to active map view.
 */
private void addPolylineObject() {
    // create boundingBox centered at current location
    GeoBoundingBox boundingBox = new GeoBoundingBox(m_map.getCenter(), 1000, 1000);
    // add boundingBox's top left and bottom right vertices to list of GeoCoordinates
    List<GeoCoordinate> coordinates = new ArrayList<GeoCoordinate>();
    coordinates.add(boundingBox.getTopLeft());
    coordinates.add(boundingBox.getBottomRight());
    // create GeoPolyline with list of GeoCoordinates
    GeoPolyline geoPolyline = new GeoPolyline(coordinates);
    MapPolyline polyline = new MapPolyline(geoPolyline);
    polyline.setLineColor(Color.BLUE);
    polyline.setLineWidth(12);
    // add GeoPolyline to current active map
    m_map.addMapObject(polyline);
    m_polylines.add(polyline);
}
Also used : ArrayList(java.util.ArrayList) GeoCoordinate(com.here.android.mpa.common.GeoCoordinate) MapPolyline(com.here.android.mpa.mapping.MapPolyline) GeoBoundingBox(com.here.android.mpa.common.GeoBoundingBox) GeoPolyline(com.here.android.mpa.common.GeoPolyline)

Example 34 with GeoCoordinate

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

the class MapFragmentView method navigateToMapMarkers.

private void navigateToMapMarkers(List<MapMarker> markers, int padding) {
    // find max and min latitudes and longitudes in order to calculate
    // geo bounding box so then we can map.zoomTo(geoBox, ...) to it.
    double minLat = 90.0d;
    double minLon = 180.0d;
    double maxLat = -90.0d;
    double maxLon = -180.0d;
    for (MapMarker marker : markers) {
        GeoCoordinate coordinate = marker.getCoordinate();
        double latitude = coordinate.getLatitude();
        double longitude = coordinate.getLongitude();
        minLat = Math.min(minLat, latitude);
        minLon = Math.min(minLon, longitude);
        maxLat = Math.max(maxLat, latitude);
        maxLon = Math.max(maxLon, longitude);
    }
    GeoBoundingBox box = new GeoBoundingBox(new GeoCoordinate(maxLat, minLon), new GeoCoordinate(minLat, maxLon));
    ViewRect viewRect = new ViewRect(padding, padding, m_map.getWidth() - padding * 2, m_map.getHeight() - padding * 2);
    m_map.zoomTo(box, viewRect, Map.Animation.LINEAR, Map.MOVE_PRESERVE_ORIENTATION);
}
Also used : MapMarker(com.here.android.mpa.mapping.MapMarker) ViewRect(com.here.android.mpa.common.ViewRect) GeoCoordinate(com.here.android.mpa.common.GeoCoordinate) GeoBoundingBox(com.here.android.mpa.common.GeoBoundingBox)

Example 35 with GeoCoordinate

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

the class MapFragmentView method addPolygonObject.

/**
 * Create a MapPolygon and add the MapPolygon to active map view.
 */
private void addPolygonObject() {
    // create an bounding box centered at current cent
    GeoBoundingBox boundingBox = new GeoBoundingBox(m_map.getCenter(), 1000, 1000);
    // add boundingbox's four vertices to list of Geocoordinates.
    List<GeoCoordinate> coordinates = new ArrayList<GeoCoordinate>();
    coordinates.add(boundingBox.getTopLeft());
    coordinates.add(new GeoCoordinate(boundingBox.getTopLeft().getLatitude(), boundingBox.getBottomRight().getLongitude(), boundingBox.getTopLeft().getAltitude()));
    coordinates.add(boundingBox.getBottomRight());
    coordinates.add(new GeoCoordinate(boundingBox.getBottomRight().getLatitude(), boundingBox.getTopLeft().getLongitude(), boundingBox.getTopLeft().getAltitude()));
    // create GeoPolygon with list of GeoCoordinates.
    GeoPolygon geoPolygon = new GeoPolygon(coordinates);
    // create MapPolygon with GeoPolygon.
    MapPolygon polygon = new MapPolygon(geoPolygon);
    // set line color, fill color and line width
    polygon.setLineColor(Color.RED);
    polygon.setFillColor(Color.GRAY);
    polygon.setLineWidth(12);
    // add MapPolygon to map.
    m_map.addMapObject(polygon);
    m_polygons.add(polygon);
}
Also used : MapPolygon(com.here.android.mpa.mapping.MapPolygon) ArrayList(java.util.ArrayList) GeoCoordinate(com.here.android.mpa.common.GeoCoordinate) GeoBoundingBox(com.here.android.mpa.common.GeoBoundingBox) GeoPolygon(com.here.android.mpa.common.GeoPolygon)

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