With marker.getTitle() you get the title of a marker, but how can I ask for the icon?
I want to ask if the icon of a marker is set to certain drawable and if so do something.
Well you can create marker with new MarkerOptions() Like this:
map.addMarker(new MarkerOptions()
.icon(BitmapDescriptorFactory.fromResource(R.drawable.house_flag))
.anchor(0.0f, 1.0f) // Anchors the marker on the bottom left
.position(new LatLng(41.889, -87.622)));
So you can simply store this data in some linked list or hash map
Without context on why you need the Icon, it is really hard to understand why you want it.
If you just want to move the marker or change the rotation you can do that by saving a variable for the Marker.
Marker allows .setPosition(LatLng) and .setRotation(Float).
Hope this helps someone since this is an old question
Related
I'm coding an android app (using java) maps-like and I use two kind of markers from Google Maps SKD: one for my current position, the other one indicates me places of intereset.
I set two different icons for these markers, how can I give to one of them the priority?
I want mu current position icon marker to be shown over all other icon markers, how can I do that?
Thank you for time :)
EDIT: here's some code I'm using for my current position marker
Drawable arrowDrawable = getResources().getDrawable(R.drawable.current_position_icon);
BitmapDescriptor arrowIcon = getMarkerIconFromDrawable(arrowDrawable);
Marker currentPositionMarker = gMap.addMarker(new MarkerOptions()
.position(new LatLng(location.getLatitude(), location.getLongitude()))
.draggable(false)
.rotation(location.getBearing())
.icon(arrowIcon)
.flat(true));
And here's some code I'm using to set my other markers
Marker marker = gMap.addMarker(new MarkerOptions()
.position(new LatLng(event.getLatitude(), event.getLongitude()))
.title("Acc. value -> " + Double.toString(event.getAccelerometerValue()))
.icon(potholeIcon)
.draggable(false));
It's the only time where I use my markers, I don't use it im my XML or in other Java code.
Render your "current position icon" after you rendered every other icon.
If it's XML then just add it last.
If it's in Java then just declare and add it to the layout last.
Can't provide code if you can't provide code though...
Edit:
Made out my mind, I'll provide some code.
XML:
<Layout...>
<Other_Icon.../>
<Other_Icon.../>
<Other_Icon.../>
<Your_Current_Position.../>
</Layout...>
Or
Java:
Layout layout=new Layout(...);
//A lot of other icons...
layout.addView(icon1);
layout.addView(icon2);
layout.addView(icon3);
//Your position icon...
layout.addView(your_current_position_icon);
Or, if you are using drag-and-drop.
Just drop the icon last.
(But it would be better if you code it instead just to make sure.)
I have an array of Marker (google maps markers) with longitude and latitude.
I want to create some sort of radar like view that'll display these markers as points where I'm looking toward their directions with an angle of 45°.
Do you guys have any idea how I can say "This marker is behind me, this marker is in front of me".
I guess I should apply cos and sin considering my orientation, but that's too blurry atm.
Hope you'll help :)
Thanks
I assume you already know your location and orientation. You can then calculate the directions of the array of markers using computeHeading() method of Google maps Geometry Library on your current location and the points. Then you can adjust those values based on your current orientation.
I want to do something like aerophotography simulator as my university project, using Google Maps Api. For this, I need dynamically change viewport of a map, but for this I have to get lat and long of center of my viewport. Is there any way to do that, using Google Maps Api standart functions?
In order to get the coordinates (LatLng) associated with the center point (x,y) of the MapView you can use the method getCameraPosition().
(Assuming your GoogleMap object is mMap)
LatLng latLng = mMap.getCameraPosition().target;
In order to animate the camera position use the method animateCamera(), something like this:
mMap.animateCamera(location);
where location is the next location you wish to show on the map (LatLng object).
I would like to create a circular route from distance.
First, I get current position, and then create a circular route based on the specified distance.
But I don't know how to achieve this at all.
I couldn't find any helpful methods in Google Maps API.
Is there any way to achieve this?
You can do that easily as Android Google Maps provides that API.
GoogleMap map;
// ... get a map.
// Add a circle in Sydney
Circle circle = map.addCircle(new CircleOptions()
.center(new LatLng(-33.87365, 151.20689))
.radius(10000)
.strokeColor(Color.RED)
.fillColor(Color.BLUE));
Take a look at this official Doc.
The only change you need to make is to pass the current location's Lat/Lng to the center method.
You can follow this tutorial to get the current location coordinates of a person.
Im having problem drawing a Circle using Google Maps v2 . The Circle displays correctly but the circle's edges are not smooth, they are quite sharp, is there any way to apply Antialising to the shape? Thanks
My code:
CircleOptions circleOptions = new CircleOptions()
.center(point)
.radius(500)
.fillColor(0x7F0000FF)
.strokeColor(Color.rgb(71, 143, 150))
.strokeWidth(2);
I know this is an old question, and I'm not completely answering it, but here's my contribute anyhow:
So far I believe there is no way of doing this in Android. The only workaround is to use a Google Maps Marker and replace its icon with a bitmap of a smooth circle. You will not be able to change it's size, but I think that is pretty much the only limitation of not using a Circle object.
To make things easier, you can even use Android Studio to create a new Image asset, choose Clip Art, and search for "brightness". The first icon will be a perfect circle, which you can then change size and color to your taste. Afterwards, just create a new Bitmap from your newly created drawable:
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.DRAWABLE_NAME_HERE);
And create a BitmapDescriptor which is used to give a Google Maps Marker its icon:
BitmapDescriptor descriptor = BitmapDescriptorFactory.fromBitmap(bitmap);
Having this object defined, you just need to set it as your Marker's icon:
Marker.setIcon(descriptor);
or
MarkerOptions.icon(descriptor);
And use these MarkerOptions to create a new Marker.
As I said, this is not the complete answer for your question, but it is the closest thing I know exists. Hope it helps somehow.