How to implement current location blue icon in Here Map

邮差的信 提交于 2019-12-22 05:53:11

问题


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.

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));

回答1:


Enabling MyLocation Layer of Google Map

googleMap.setMyLocationEnabled(true);



回答2:


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)



回答3:


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.




回答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) {

}



回答5:


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;
}



回答6:


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.




回答7:


/* 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));



回答8:


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.



来源:https://stackoverflow.com/questions/44786552/how-to-implement-current-location-blue-icon-in-here-map

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!