Google Map Marker Rotation not change when rotate map - android

I am using android Google Map API v2 to build a navigation application on android phone. For direction of movement, I used a marker with arrow image as the marker (the image have a dot and a arrow on top of it). I tried to use .rotation to set orientation of the marker according to the direction of movement.
The problem is that when I rotate Google Map, the Map's rotation change but the orientation of marker is unchanged.
I am looking for a way to set rotation of the marker relative to Map's rotation (so when an user rotate map, the marker will rotate accordingly).
Or if anyone know how to build direction arrow other than my primitive way, please enlighten me. Thank you :)

By default, markers are oriented against the screen, and will not rotate or tilt with the camera. Flat markers are oriented against the surface of the earth, and will rotate and tilt with the camera.
You can make the marker flat by calling flat(true) as in the following example:
Marker perth = mMap.addMarker(new MarkerOptions()
.position(PERTH)
.flat(true));

call setRotation and that will do the trick!
e.g.
static final LatLng PERTH = new LatLng(-31.90, 115.86);
Marker perth = mMap.addMarker(new MarkerOptions()
.position(PERTH)
.anchor(0.5,0.5)
.rotation(90.0));
Code Ref

Related

marker is not stick to given position on map while spinning the map

I observed strange behavior of marker on map while spinning/rotating the map from one direction to other.
In my code I have moved the map center point to upward from the marker location to display the current ongoing cursor at the bottom of the map as per the suggestion by Nikunj in this post. it seems working fine while in zoomed view and when the polylinie is drown vertically.
when the polyline is drown towards left or right the marker is displayed in opposite direction but the expectation of marker is to draw on the polyline.
For placing marker what i do is:
getting the nearest latlng of the polyline to the current location and assigning it to marker and animating the parking to the polyline's point.
Following are the snapshots of the issue.
1) when polyline is vertically straight :
2) when polyline is in right side :
3) when polyline is in left side :
if anybody has faced the same issue please suggest me to solve this issue.
You need to set the anchor of the image on your marker. For example:
MarkerOptions markerOptions = new MarkerOptions()
// Set all the options for your marker
.anchor(0.5, 0.5);

How can I make a google map ground overlay that points along the direction of road

How can I create an overlay image of an arrow that points to the driving direction as such.
The road directions vary significantly, the angle, curve is different from time to time, so the arrow has to be flexible enough to adapt to road condition. How can I do that?
Thanks
Not long ago Google added the Flat Marker option to the Google Maps API V2, take a look here:
https://developers.google.com/maps/documentation/android/marker#flatten_a_marker
You can create it like so:
static final LatLng PERTH = new LatLng(-31.90, 115.86);
Marker perth = mMap.addMarker(new MarkerOptions()
.position(PERTH)
.flat(true)
.rotation(90.0));
and get the rotation parameter by using the bearing sensor of the phone:

GroundOverlay is not displaying but marker is displaying in Android GoogleMap v2

I am moving from Android googlemap v1 to v2. I found that to display my own icons I have to use GroundOverlay(In v1 I used Overlay ) Is there any other good solution?
Can I update the GroundOverlay location whenever I receive the location updates? (move the object) Google says "A ground overlay is an image that is fixed to a map"
Even if I add GroundOverlay I don't see it in my map. It just locate to Africa. No Icon. When I add Marker I can see that. But not GroundOverlay.
BitmapDescriptor image =
BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_BLUE);
LatLngBounds bounds = new LatLngBounds (new LatLng(00.00, 00.00), new LatLng(00.00, 00.00)); // get a bounds
GroundOverlayOptions goo = new GroundOverlayOptions();
goo.image(image);
goo.positionFromBounds(bounds);
goo.transparency(0);
goo.visible(true);
// Adds a ground overlay with 50% transparency.
GroundOverlay groundOverlay = googleMap.addGroundOverlay(goo);
I have a demo in 2 days I really want this to work. Please help.
I found the problem. The problem is with the zoom. The GroundOverlay is very small to see.
final LatLng cordination = new LatLng(40.714086, -74.228697);
goo.position(cordination, 500000f);
Now my problem is when I zoom the map. The GroundOverlay also zooming. I want this not to zoom and work like a Marker. Any one know how to do Pls respond.
The ground overlay is something that behaves as if it is laying on the ground. So it will be turned, zoomed etc. together with the map.
So why do you prefer ground overlay over markers if you want to work it like a marker? You can use your own image also for a marker:
BitmapDescriptor image = ....;
MarkerOptions options = new MarkerOptions();
options.position(coordinate);
options.icon(image);
googleMap.addMarker(options);

Map marker on Google Android Maps API v2 with set bounds

In APIv1 I was drawing markers like this:
Drawable flag = getResources().getDrawable(R.drawable.flagfinish);
flag.setBounds(0, -flag.getIntrinsicHeight(), flag.getIntrinsicWidth(), 0);
and it was working - left bottom corner of picture was in center of LatLng. But how could I draw something like this in APIv2? I tried this:
Marker hc = mMap.addMarker(new MarkerOptions()
.position(HC)
.title("Hlohovec")
.snippet("Hlohovec")
.icon(BitmapDescriptorFactory.fromResource(R.drawable.flagfinish)));
but this is moved to left (I want to draw a flag with pole on left so this doesn't pin it where I want).
Is there any possible way to do this? And I don't want to use GroundOverlayOptions because it is changing with zoom.
Thanks for any answers.
you need to change the Anchor position of the marker image when you create the marker
from the docs:
The point on the image that will be placed at the LatLng position of the marker. This defaults to the middle of the bottom of the image.

Android GoogleMap V2 how to add markers with user screen size?

I am working on google map v2 and i got a question,
i can now add a single marker for my current location
and i know the concept about adding markers,
but now i want to add more markers which near my current location,
and there are thousands of markers can add into the map due to the database
so how can i add markers within a range of area which is surround my current location,
and the range will be the user's screen size.
Thus more markers when zoom out and less markers when zoom in.
or maybe radius set as 5km of if current location
Thanks guys
marker = map.addMarker(new MarkerOptions().position(
new LatLng(location.getLatitude(), location.getLongitude()))
.title("my position").icon(BitmapDescriptorFactory
.defaultMarker(BitmapDescriptorFactory.HUE_AZURE)));
use this approach:
var lat=new_marker.getPosition().lat();
var lng=new_marker.getPosition().lng();
var target = new GLatLng(lat,lng);
var center= new GLatLng(yourLat, yourLng);//your gps position
var distance = center.distanceFrom(target) / 1000;//meters to km
if(distance < radius){//where radius = 5Km
new_marker.setMap(map);//add to map
}
Look this example is similar that you are looking for, he wants to draw a circle that resize to screen size: Google map api V2 resize screen to match a circle drawn

Categories

Resources