How can I add this type of animation in google map marker in android?
If user tap icon for more than two second then marker clickable
How can set this in android?
How can I add this type of animation in google map marker in android?
If user tap icon for more than two second then marker clickable
How can set this in android?
Here's an example of the circle approach - first the recording followed by the code.
The radius growth is linear here but is obviously a different function in your example (it slows down as it expands) so you'll need to work with that.
public void pulseCircleTest() {
// arbitrary point
LatLng pt = new LatLng(39.171755, -86.510632);
// move map to point of interest
CameraPosition cp = CameraPosition.builder().target(pt).zoom(8.0F).build();
mMap.animateCamera(CameraUpdateFactory.newCameraPosition(cp));
// create a circle and start animation
int color = Color.BLUE;
float initialRadius = 10;
float maxRadius = 20000f;
CircleOptions co = new CircleOptions().center(pt).radius(initialRadius).strokeColor(color).fillColor(color).strokeWidth(1.0f);
Circle c = mMap.addCircle(co);
Circle c2 = mMap.addCircle(co);
final Handler h = new Handler();
h.postDelayed(new Fader(h,c, initialRadius, maxRadius, Color.BLUE, co), 300);
h.postDelayed(new Fader(h,c2, initialRadius, maxRadius, Color.BLUE, co), 750);
}
private class Fader implements Runnable {
private float radius, initialRadius, maxRadius;
private int baseColor, color, initialColor;
private Handler h;
private Circle c;
private float radiusJump = 400;
int numIncrements, alphaIncrement;
private CircleOptions co;
public Fader(Handler h, Circle c, float initialRadius, float maxRadius, int initialColor, CircleOptions co) {
this.initialRadius = initialRadius;
this.initialColor = initialColor;
this.maxRadius = maxRadius;
this.h = h;
this.c = c;
this.co = co;
reset();
}
private void reset() {
radius = initialRadius;
this.color = initialColor;
this.baseColor = initialColor;
numIncrements = (int)((maxRadius - initialRadius) / radiusJump);
alphaIncrement = 0x100 / numIncrements;
if (alphaIncrement <= 0) alphaIncrement = 1;
}
public void run() {
int alpha = Color.alpha(color);
radius = radius + radiusJump;
c.setRadius(radius);
alpha -= alphaIncrement;
color = Color.argb(alpha, Color.red(baseColor), Color.green(baseColor), Color.blue(baseColor));
c.setFillColor(color);
c.setStrokeColor(color);
if (radius < maxRadius) {
h.postDelayed(this, 25);
} else {
c.remove();
reset();
c = mMap.addCircle(co);
h.postDelayed(this, 2000);
}
//done
}
}
NOTE: This is not the right solution but just a hack to work around .
In your layout take Google map fragment and an ImageView
in center
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:src="@drawable/ic_customerlocation" />
</RelativeLayout>
now take a gif image of the animation you want and load the gif image into ImageView
using Glide
or something else
If you want to know the location if user moves the map you can use onCameraIdle()
method to get the new location
@Override
public void onCameraIdle() {
if (mGoogleMap != null ) {
CameraPosition cameraPosition = mGoogleMap.getCameraPosition();
LatLng latLng = cameraPosition.target;
}
}