Search in sources :

Example 21 with GeoCoordinate

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

the class MapFragmentView method addMarkerAtPlace.

// Place markers handling helpers
private void addMarkerAtPlace(PlaceLink placeLink) {
    Image img = new Image();
    try {
        img.setImageResource(R.drawable.marker);
    } catch (IOException e) {
        e.printStackTrace();
    }
    MapMarker mapMarker = new MapMarker();
    mapMarker.setIcon(img);
    mapMarker.setCoordinate(new GeoCoordinate(placeLink.getPosition()));
    Map map = m_mapFragment.getMap();
    map.addMapObject(mapMarker);
    m_mapObjectList.add(mapMarker);
}
Also used : MapMarker(com.here.android.mpa.mapping.MapMarker) GeoCoordinate(com.here.android.mpa.common.GeoCoordinate) IOException(java.io.IOException) Image(com.here.android.mpa.common.Image) Map(com.here.android.mpa.mapping.Map)

Example 22 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 = (MapFragment) m_activity.getFragmentManager().findFragmentById(R.id.mapfragment);
    // Set path of isolated disk cache
    String diskCacheRoot = Environment.getExternalStorageDirectory().getPath() + File.separator + ".isolated-here-maps";
    // Retrieve intent name from manifest
    String intentName = "";
    try {
        ApplicationInfo ai = m_activity.getPackageManager().getApplicationInfo(m_activity.getPackageName(), PackageManager.GET_META_DATA);
        Bundle bundle = ai.metaData;
        intentName = bundle.getString("INTENT_NAME");
    } catch (PackageManager.NameNotFoundException e) {
        Log.e(this.getClass().toString(), "Failed to find intent name, NameNotFound: " + e.getMessage());
    }
    boolean success = com.here.android.mpa.common.MapSettings.setIsolatedDiskCacheRootPath(diskCacheRoot, intentName);
    if (!success) {
    // Setting the isolated disk cache was not successful, please check if the path is valid and
    // ensure that it does not match the default location
    // (getExternalStorageDirectory()/.here-maps).
    // Also, ensure the provided intent name does not match the default intent name.
    } else {
        if (m_mapFragment != null) {
            /* Initialize the MapFragment, results will be given via the called back. */
            m_mapFragment.init(new OnEngineInitListener() {

                @Override
                public void onEngineInitializationCompleted(OnEngineInitListener.Error error) {
                    if (error == Error.NONE) {
                        m_map = m_mapFragment.getMap();
                        m_map.setCenter(new GeoCoordinate(49.259149, -123.008555), Map.Animation.NONE);
                        m_map.setZoomLevel(13.2);
                    } else {
                        Toast.makeText(m_activity, "ERROR: Cannot initialize Map with error " + error, Toast.LENGTH_LONG).show();
                    }
                }
            });
        }
    }
}
Also used : PackageManager(android.content.pm.PackageManager) Bundle(android.os.Bundle) ApplicationInfo(android.content.pm.ApplicationInfo) GeoCoordinate(com.here.android.mpa.common.GeoCoordinate) OnEngineInitListener(com.here.android.mpa.common.OnEngineInitListener)

Example 23 with GeoCoordinate

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

the class Venue3dActivity method initialize.

private void initialize() {
    setContentView(R.layout.venues3d);
    m_activity = this;
    // Search for the map fragment in order to finish setup by calling init().
    m_mapFragment = getMapFragment();
    m_venueIdEditText = (EditText) findViewById(R.id.venueIdEditText);
    m_mainControlLayout = (LinearLayout) findViewById(R.id.venueOpeningLayout);
    m_routeInfoLayout = (LinearLayout) findViewById(R.id.routeInfoLayout);
    m_routingOptionType = (Spinner) findViewById(R.id.routeOptionType);
    m_routingOptionMode = (Spinner) findViewById(R.id.routeOptionMode);
    m_routeStartGuideText = (TextView) findViewById(R.id.startLocationGuideText);
    m_routeEndGuideText = (TextView) findViewById(R.id.endLocationGuideText);
    m_routingFromText = (TextView) findViewById(R.id.startLocationText);
    m_routingToText = (TextView) findViewById(R.id.endLocationText);
    m_showRouteButton = (Button) findViewById(R.id.buttonShowRoute);
    // Fill dropDownList with routing type names.
    String[] type_values = new String[] { "Fastest", "Shortest" };
    configureSpinner(m_routingOptionType, type_values);
    // Fill dropDownList with routing mode names.
    String[] mode_values = new String[] { "Car", "Pedestrian", "Public Transport" };
    configureSpinner(m_routingOptionMode, mode_values);
    // Set default values to: Fastest and Pedestrian.
    m_routingOptionType.setSelection(0);
    m_routingOptionMode.setSelection(1);
    // Set path of disk cache
    String diskCacheRoot = m_activity.getFilesDir().getPath() + File.separator + ".isolated-here-maps";
    // This will use external storage to save map cache data, it is also possible to set
    // private app's path
    String path = new File(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);
    // Initialise the Map Fragment to have a map created and attached to
    // the fragment
    m_mapFragment.init(new OnEngineInitListener() {

        @Override
        public void onEngineInitializationCompleted(Error error) {
            if (error == Error.NONE) {
                // retrieve a reference of the map from the map fragment
                m_map = m_mapFragment.getMap();
                // Set the map center, zoom level, orientation and tilt
                m_map.setCenter(new GeoCoordinate(49.196261, -123.004773, 0.0), Map.Animation.NONE);
            } else {
                System.out.println("ERROR: Cannot initialize Map Fragment" + error.toString());
                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();
            }
        }
    }, new VenueServiceListener() {

        @Override
        public void onInitializationCompleted(InitStatus result) {
            if (result == InitStatus.ONLINE_SUCCESS || result == InitStatus.OFFLINE_SUCCESS) {
                // Register the activity class as VenueMapFragment.VenueListener
                m_mapFragment.addListener(m_activity);
                // Set animations on for floor change and venue entering
                m_mapFragment.setFloorChangingAnimation(true);
                m_mapFragment.setVenueEnteringAnimation(true);
                // Ask notification when venue visible; this notification is
                // part of VenueMapFragment.VenueListener
                m_mapFragment.setVenuesInViewportCallback(true);
                // Add listener for onCombinedRouteCompleted.
                m_mapFragment.getRoutingController().addListener(m_activity);
                // Add listener for map gesture.
                m_mapFragment.getMapGesture().addOnGestureListener(m_activity, 0, false);
                // Create floor change widget
                m_floorsController = new VenueFloorsController(m_activity, m_mapFragment, (ListView) findViewById(R.id.floorListView), R.layout.floor_item, R.id.floorName, R.id.floorGroundSep);
                m_initCompleted.set(true);
                // Start position tracking
                PositioningManager positioningManager = PositioningManager.getInstance();
                positioningManager.start(PositioningManager.LocationMethod.GPS_NETWORK_INDOOR);
                // Set positioning indicator visible
                PositionIndicator positionIndicator = m_mapFragment.getPositionIndicator();
                positionIndicator.setVisible(true);
            }
        }
    });
}
Also used : VenueServiceListener(com.here.android.mpa.venues3d.VenueService.VenueServiceListener) DialogInterface(android.content.DialogInterface) GeoCoordinate(com.here.android.mpa.common.GeoCoordinate) OnEngineInitListener(com.here.android.mpa.common.OnEngineInitListener) PositionIndicator(com.here.android.mpa.mapping.PositionIndicator) PositioningManager(com.here.android.mpa.common.PositioningManager) InitStatus(com.here.android.mpa.venues3d.VenueService.InitStatus) File(java.io.File)

Example 24 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() {
    m_mapFragment = getMapFragment();
    m_laneInfoView = m_activity.findViewById(R.id.laneInfoLayout);
    // 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 == OnEngineInitListener.Error.NONE) {
                    m_mapFragment.getMapGesture().addOnGestureListener(gestureListener, 100, true);
                    // retrieve a reference of the map from the map fragment
                    m_map = m_mapFragment.getMap();
                    m_map.setZoomLevel(19);
                    m_map.addTransformListener(onTransformListener);
                    PositioningManager.getInstance().start(PositioningManager.LocationMethod.GPS_NETWORK);
                } else {
                    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();
                }
            }
        });
        m_mapFragment.addOnMapRenderListener(new OnMapRenderListener() {

            @Override
            public void onPreDraw() {
                if (m_positionIndicatorFixed != null) {
                    if (NavigationManager.getInstance().getMapUpdateMode().equals(NavigationManager.MapUpdateMode.ROADVIEW)) {
                        if (!m_returningToRoadViewMode) {
                            // when road view is active, we set the position indicator to align
                            // with the current map transform center to synchronize map and map
                            // marker movements.
                            GeoCoordinate geoCoordinate = m_map.pixelToGeo(m_mapTransformCenter);
                            if (geoCoordinate != null && geoCoordinate.isValid()) {
                                m_positionIndicatorFixed.setCoordinate(geoCoordinate);
                            }
                        }
                    }
                }
            }

            @Override
            public void onPostDraw(boolean var1, long var2) {
            }

            @Override
            public void onSizeChanged(int var1, int var2) {
            }

            @Override
            public void onGraphicsDetached() {
            }

            @Override
            public void onRenderBufferCreated() {
            }
        });
    }
    m_activity.findViewById(R.id.calculate).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            calculateAndStartNavigation();
        }
    });
}
Also used : DialogInterface(android.content.DialogInterface) OnMapRenderListener(com.here.android.mpa.mapping.OnMapRenderListener) GeoCoordinate(com.here.android.mpa.common.GeoCoordinate) OnEngineInitListener(com.here.android.mpa.common.OnEngineInitListener) View(android.view.View) RouteWaypoint(com.here.android.mpa.routing.RouteWaypoint) File(java.io.File)

Example 25 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) {
                    m_map = m_mapFragment.getMap();
                    m_map.setCenter(new GeoCoordinate(49.259149, -123.008555), Map.Animation.LINEAR);
                    m_map.setZoomLevel(13.2);
                } else {
                    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)

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