How to implement current location blue icon in Here Map
Asked Answered
B

8

8

I am working with the Here Map SDK and I need to show a blue icon with circle animation for current location like in image.

enter image description here

Can anyone tell me how to do it.

Right now I have code which sets the icon only which is blue dot. I don't know how to add circle animation to it.

Note that the mMap reference is a Map object from the Here Android SDK.

 mMap.getPositionIndicator().setVisible(true);
                    mMap.getPositionIndicator().setZIndex(0);
                    mMap.setZoomLevel(15);
                    mMap.getPositionIndicator().setAccuracyIndicatorVisible(true);
                    mMap.getPositionIndicator().setMarker(createImage(R.drawable.ic_location_dot));
Brosine answered 27/6, 2017 at 17:36 Comment(0)
G
4

Try this one:

mMap.setMyLocationEnabled(true);

It enables or disables the my-location layer. While enabled and the location is available, the my-location layer continuously draws an indication of a user's current location and bearing, and displays UI controls that allow a user to interact with their location (for example, to enable or disable camera tracking of their location and bearing).

Much better if you place it under:

@Override
public void onMapReady(GoogleMap googleMap) {

}
Godber answered 12/7, 2017 at 3:38 Comment(1)
saw "Here" maps in the title, still came here (I was in need of a solution for Google Maps). Worth it!!Berstine
C
1

You can control the HERE Maps current location icon through com.here.android.mpa.mapping.PositionIndicator class.

Its instance is kept in com.here.android.mpa.mapping.MapView that might be wrapped in a fragment like com.here.android.mpa.mapping.SupportMapFragment.

Examples:

mapFragment.getPositionIndicator().setVisible(true)
mapView.getPositionIndicator().setAccuracyIndicatorVisible(true)
Chilon answered 23/7, 2019 at 8:0 Comment(0)
D
0

For javascript you can use

map.addObject(new H.map.Circle(
// The central point of the circle
{lat:28.6071, lng:77.2127},
// The radius of the circle in meters
1000,
{
  style: {
    strokeColor: 'rgba(55, 85, 170, 0.6)', // Color of the perimeter
    lineWidth: 2,
    fillColor: 'rgba(0, 128, 0, 0.1)'  // Color of the circle
  }
}
));

There should be a similar implementation for android.

Deaton answered 11/7, 2017 at 21:23 Comment(0)
S
0

I have tested this code successfully and call addPulsatingEffect(Location userLocation) method with user's current location.

private Circle lastUserCircle;
private static final long PULSE_DURATION = 2000;
private static final float RADIUS = 200.0f;
private ValueAnimator lastPulseAnimator;

private void addPulsatingEffect(Location userLocation){

final LatLng userLatlng = new LatLng(userLocation.getLatitude(), userLocation.getLongitude());

if(lastPulseAnimator != null){
    lastPulseAnimator.cancel();
}

if(lastUserCircle != null) {
    lastUserCircle.setCenter(userLatlng);
}

lastPulseAnimator = valueAnimate(RADIUS, new ValueAnimator.AnimatorUpdateListener() {

    @Override
    public void onAnimationUpdate(ValueAnimator animation) {

        if(lastUserCircle != null)
            lastUserCircle.setRadius((Float) animation.getAnimatedValue());
        else {
            lastUserCircle = mMap.addCircle(new CircleOptions()
                    .center(userLatlng)
                    .radius((Float) animation.getAnimatedValue())
                    .strokeColor(Color.BLUE)
                    .strokeWidth(4.0f));
        }
    }
});
}

protected ValueAnimator valueAnimate(float radius, ValueAnimator.AnimatorUpdateListener updateListener){

ValueAnimator valueAnimator = ValueAnimator.ofFloat(0, radius);
valueAnimator.setDuration(PULSE_DURATION);
valueAnimator.addUpdateListener(updateListener);
valueAnimator.setRepeatCount(ValueAnimator.INFINITE);
valueAnimator.setRepeatMode(ValueAnimator.RESTART);

valueAnimator.start();
return valueAnimator;
}
Santoro answered 12/7, 2017 at 6:21 Comment(3)
I couldnt find many of the classes like Circle, LatLng, addCircle method for map etc. i am using here map and mMap is Map object for me.Brosine
yes bro, "mMap" is a object of "com.google.android.gms.maps.GoogleMap", "Circle" is a object of "com.google.android.gms.maps.model.Circle", "LatLng" class is a object of "com.google.android.gms.maps.model.LatLng". Try with importing those classes. It will work definitely...Santoro
I am working with Here Map SDK. thats why this is not working for meBrosine
P
0

For this use case, it is better to write your own position indicator.

Three things to do: 1: Register for PositioningManager callbacks which relay the updated position to your code. 2: Create a MapMarker with your desired image and add it to the map. 4: Create a MapCircle with the desired color and add it to the map. The radius for the circle should be set to the accuracy parameter of the Positioning Manager callback.

The logic to do this is to update the radius of the MapCircle, as well as update the GeoCoordinate of both the MapMarker and MapCircle whenever a new position is received from PositioningManager.

You can be fancy and add animations by using Timers and such to animate any accuracy changes.

Powerhouse answered 14/7, 2017 at 6:9 Comment(0)
S
0

Enabling MyLocation Layer of Google Map

googleMap.setMyLocationEnabled(true);
Snowmobile answered 17/7, 2017 at 7:16 Comment(3)
wptrafficanalyzer.in/blog/…Snowmobile
refer this linkSnowmobile
this question is about here maps and not google mapsConflict
D
0
/* create a MarkerOptions */
MarkerOptions mOptions = new MarkerOptions();

/* create a MarkerInfoAdapter */
MarkerInfoAdapter infoAdapter = new MarkerInfoAdapter(MapsActivity.this.getLayoutInflater());

/* set MarkerInfoAdapter into your Map object */
MapFragment googleMap = FragmentManager.FindFragmentById<MapFragment> (Resource.Id.map);

/* get the GoogleMap object */
GoogleMap myMap = googleMap.getMapAsync(this);

/* set myMap type */
myMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);

/* set the MarkerInfoAdapter */
myMap.clear(); /* 
myMap.setInfoWindowAdapter(infoAdapter);


/* you must have your current location's LatLng  */
mOptions.position(currentLatLng); /* reach the position of the LatLng for that mark */

/* set the icon for your current location using BitmapDescriptorFactory */
mOptions.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_BLUE));
myMap.addMarker(mOptions);

/* modify your marker icon to HUE_BLUE */                       mOptions.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_BLUE));
Demijohn answered 18/7, 2017 at 4:58 Comment(0)
D
0

I had the same problem as you and after two weeks of try all kind of options, this lines of code worked for me so yo can show the "blue icon"

m_map.setCenter(new GeoCoordinate(latitudeGPS, longitudeGPS, 0.0),Map.Animation.NONE);
                m_mapFragment.getPositionIndicator().setVisible(true);
                m_map.getPositionIndicator().setAccuracyIndicatorVisible(true);
                Log.d("initialize bolita", "" + 1.1 );
                PositioningManager.getInstance().start(PositioningManager.LocationMethod.GPS_NETWORK);m_map.addMapObject(m_positionIndicatorFixed);

Make sure you have requested all the permissions on your manifest.

Digiovanni answered 28/2, 2018 at 4:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.