Icon on top of another icon in Android - java

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

Related

How to display user position on custom made map in indoor navigation?

I am creating a small indoor navigation android application using wifi fingerprinting. Since it is a small scale application I am using a custom made map(which is basically a png image)I want to show the location of the user on a particular spot on the image and update it accordingly as the user moves. So what is the best way to do it?I thought of dividing image like x-y axis and placing the dot on the axis according to value(Tell me this also).
It involves a lot of Bitmap manipulation . Take that marker as an ImageView which you should be able to put it across your FrameLayout inside which you would have the root Map imageView/ map view and then over the top of it . you should be able to put that marker on top of it. but if its a static marker image. then you should be able to use LayoutParams and put on top of the root map view.
There are hundreds of ways.
One easy way would be to use:
https://github.com/chrisbanes/PhotoView
That lib handles scaling, panning, etc and even provides access to the matrix used.
It is important to note too that the users coordinates need to be translated into scale.
In one of my apps, I dont handle user locations, but I allow a user to put pins on the map. My Pin object contains XY coords relative to the original map size.
To convert to the device/image scale size, I do this:
float[] convertedPin = {pin.getX(), pin.getY()};
getImageMatrix().mapPoints(convertedPin);
getImageMatrix() is provided with the library posted above.
Then, I modified the libs onDraw():
for (Pin pin : pins) {
if (pin.isVisible()) {
float[] goal = {pin.getX(), pin.getY()};
getImageMatrix().mapPoints(goal);
if (pin.getPinBitmap() != null) {
float pinSize = TypedValue.applyDimension(COMPLEX_UNIT_DIP, pin.getPinSize(), getContext().getResources().getDisplayMetrics());
canvas.drawBitmap(pin.getPinBitmap(), goal[0] - (pinSize / 2f), goal[1] - pinSize, null);
}
canvas.save();
}
}

creating a circular route from distance in android app

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.

Zoom Maps do , width and length of the route Android Studio

I am looking for a solution to my problem. My application uses Google Maps and Google Play Service. My application gets the user's position and writes to the array. On the basis of the points I make a route. When I display it on the map, the map is far away. I'd like to bring. The problem is that the route can have a length from 50m to 1000km. Someone please help me ? Thank you very much!
My maps can look as below (BLUE LINE)!
I see you already save the user's position, so it's pretty simple. Just pick the first and last positions and use a CameraUpdate to display the route to the user:
LatLngBounds.Builder builder = new LatLngBounds.Builder();
builder.include(first_position_latlng);
builder.include(last_position_latlng);
LatLngBounds bounds = builder.build();
CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(bounds, padding_if_any);
mMap.animateCamera(cu);
Just keep in mind that this works for simple routes like the one you linked. For more complex ones instead of the first and last position, you'll need to find the the furthest southwest and northeast points

How to get Icon of Google Maps marker?

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

Anti-Alising Circle shape Google Maps V2 Android

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.

Categories