I'm struggling to find a solution to the following problem in Android:
there should be custom views on the map which should animate/expand/etc just like regular views. For instance I need a current user location indicator which "pulsates" on the map, or I need some kind of marker clustering with the following behavior: when I tap on the cluster all the pois from this cluster are animated out evenly spread around the cluster so you can click them individually.
I've seen solutions involving periodically drawing into bitmap canvas and then updating the marker's bitmap, but it doesn't help when you want to click on the expanded items in the bitmap, also animating a marker with updating it's bitmap would look horrible and clunky.
On iOS for example there is a class MKAnnotationView which you can override and draw however you want, why doesn't android have such a simple feature? How can this be achieved in Android? Any help is appreciated.
Related
I want to display a custom image below a marker in my Android App. I see no available documentation so that I can execute this.
Have a look at what I want to achieve here. It is like an indicator and should be anchored to the markers and the distance between markers and image should not vary.
Building custom overlay specifically circle with radius(colored) in Android MapBox GL. It allows to change radius dynamically using seekbar.
I'm trying to build some custom markers and I used SimpleCircleView but Im having problem trying to display it in MapBox GL android, and it created lots of bugs.
The map touch event is unresponsive once my CircleOverlay is displayed in map
The marker doesnt stay in its coordinates once i zoom-in , zoom-out.
Updating markers doesnt work, So I have to remove then add again the marker.
The color does not match the color that I set in marker.
I'll limit my posting on code, because this repo is mine and to keep the problem understandable.
In building custom overlay I have to make these classes:
CircleMarkerView.java - The Custom Marker View
[CircleMarkerViewOptions.java] (https://github.com/spurdow/SimpleCircleView/blob/master/app/src/main/java/com/spurdow/circleviewtest/CircleMarkerViewOptions.java) - This is to be used with CircleMarkerView
SimpleCircleView.java - This is my custom view for dynamic circle changing its radius etc.
MainActivityMapBox - This is where to put it all
This is an example of the code in the repo.
Does anybody have any idea how to do this simply?
Or
Is there another way of building an overlay dynamically?
Or
Is it possible to create a circle bitmap dynamically and convert it to icon when seekbar's progress is changing?
1. The map touch event is unresponsive once my CircleOverlay is displayed in map
This is an issue we plan to address by next release, you can follow progress on this here.
2. The marker doesnt stay in its coordinates once i zoom-in , zoom-out.
The could be because you aren't anchoring the marker icon correctly using .setAnchor() or your icon has padding around it. For a circle, you'll want to anchor centered (using 0.5f). A bug was introduced right before the previous stable release that causes anchoring not to work correctly. If this is an issue, use the 4.2.0-SNAPSHOT.
3. Updating markers doesnt work, So I have to remove then add again the marker.
Could you elaborate on this issue? You might be using
Marker marker = mapboxMap.addMarker(new MarkerViewOptions()...
When you should be using:
MarkerView marker = mapboxMap.addMarker(new MarkerViewOptions()...
Which will give you more options to update markers.
4. The color does not match the color that I set in marker.
Could you clarify what you mean by this?
It sounds like you are wanting to do what this example does in the testapp? I would follow along with the code found there.
I have a particular need with a mapView and i can't find any good solution.
I have a Mapview with some markers displayed on it, and it works perfectly.
My need is that i want to put a kind of layer/background on the screen, in order to "mask" the map, but i always want to see the markers, and keep all the mapview functionnalities (zoom, move, etc.)
Is there any solution available to do it?
I hope you understand my need.
Many thanks in advance.
Create an overlay that mask (cover) the part of the map that you want to cover. In the onDraw() of this oevrlay just draw something that achive your mask requirements (areas, colors and opacity).
To ensure that markers are always visible, you need to add the overlay with markers after you add the overlay that mask map to the mapView.getOverlays.add().
Enjoy it.
I am trying to develop a map(basically a static image) in ANDROID where I can show different items(drawn in the map itself). How can I do that. I've tried different approaches. The map is basically a static image. Please help!
More details on what you're trying to do would help to answer this question correctly. What methods have you tried already?
Are you trying to just draw static images overlaid each other in a view?
Are you trying to draw an actual geographic map with a MapView or something along those lines?
If you're trying to draw an image over another, you can do it in a number of ways.
You could use a RelativeLayout to assign absolute positions your overlay images (most likely each in the form of an ImageView). Here's a good SO answer that covers assigning absolute positions to children in an RelativeLayout: Set the absolute position of a view
You could load the base image (your map) and the overlays into Bitmap objects. Then, using a Canvas object you could draw them in specified locations. Look at the various Canvas.drawBitmap() functions to see your options on specifying the position of the Bitmap you are drawing. You could also draw shapes instead of images using the drawRect(), drawRoundRect(), drawLine(), or drawOval() methods. There are other options as well. Read the Canvas documentation.
Otherwise, if you're trying to draw a movable map of some sort, then you'll need to use a MapView or MapActivity. There are classes that you use to overlay images in specified locations on the map. This won't be a static image, but a movable map along with the overlays that stay in the specified location. You'll use the ItemizedOverlay class to act as a data structure to store your actual overlay images (wrapped in the OverlayItem class).
This is a great tutorial that goes into depth about what I'm talking about:
http://developer.android.com/guide/tutorials/views/hello-mapview.html
I have faced some problems with the Android MapView API. I get OverlayItems from a database which I want to display in a MapView. If I'm displaying 100 Icons, I have no issues, but if it gets more - like 500 Items in one City - it first looks really bad, while second it slows down a lot. Unfortunately my goal is to display 10000 of them. I think one solution can be to register a listener to ZoomLevels to make them appear/dissapear, but I couldn't find that functionality. Second, I couldn't find a function to scale my Overlays with the Zoom of the Map.
Any Ideas are very welcome
There is a very strange behavior in ItemizedOverlay draw method. When you say: Draw line from (x,y) to (x1,y1) the draw method is called about 20-30-40 times - i don't know why. It is acceptable when you draw one line, but when you draw a thousands of lines,icons and so on...it is very very bad! To solve this problem you should create a cached overlay. This is overlay that catches the first draw, creates the object and then prevents the future draws that do the same draw.
A cluster is a dozen of icons behind one icon. For example if you have 1000 markers on the map, in a specific minimal zoom level you can not see each marker separately - it becomes a mess of icons and colors and so on. And instead of 100 markers that are very very close one by one you place a cluster marker. And on zoom in remove this cluster and create another clusters...do this until the markers became far enough away and you can seen them divided.
Check this: Cluster markers
Take the following approaches:
Create a cached overlay to prevent multiple drawing of same clusters;
Draw in thread;
Cluster your markers depending on zoom level and marker proximity.
Each time you draw in the overlay, check for sure is the current marker inside of the visible part of the screen. If it is not, do no draw it!
I had a similar problem with the icon size and zoom level in my application. What I ended up doing was having 2 sets of overlays containing the markers, one with a "zoomed in" icon and one with a "zoomed out" icon. Then just changed the overlay at a certain zoom level (using a zoom poller - On zoom event for google maps on android)