How to Display thousands of OverlayItems in an Android MapView - android

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)

Related

Generate "out of view" markers indicators on a map with React Native

For a project, I have to indicate, with colored arrows, in which direction are the markers that aren't shown in the visible region.
When the user scrolls, or zoom on the map, the arrows move accordingly to where the not visible markers are compared to the current center of the visible region.
Here is a picture that demonstrate what is needed :
I am using react-native-mapview and added regular views over the map to show the indicators.
I've started working on this by comparing the coordinates and calculating the point of intersection between lines (border lines and line made by the 2 coordinates) at each frame. It works fine on iOS but is pretty laggy on Android, especially chan there are a lot of markers involved.
What would be the best and optimized way to do this ?
Maybe you could try using Animated.View instead regular view. It may render more fluently?
pass tracksViewChanges={false} to Markers https://github.com/react-native-community/react-native-maps/blob/master/docs/marker.md

show/hide polygons based on what the screen is showing

I'm using google maps on my android app, loading multiple polygons to the map which causes a significant lag.
My map is pretty zoomed in, so many polygons aren't even shown on the screen (but still causing lag cause they are exist).
is there a way to only show polygons that are contained in the screen and hide the others? (polygons are shown or get hidden based on what the screen view)
Thanks
Get bounds for visible part, something like this:
LatLngBounds bounds = mMap.getProjection().getVisibleRegion().latLngBounds;
Then determine if your polygon is inside visible part bounds (by calling bounds.contains(....) for each polygon vertex). If not, just don't draw polygon.
Of course, you need to handle camera change events to recalculate visible bounds and draw missing polygons if needed (when their part of map become visible).

Drawing on the MapFragment, while keeping some elements visible

I'm developing an application that has the following goal:
Using the google maps android API 2 I get my current position, and as I start walking the application starts drawing the route I take
The twist is that the map is a "blind" map. Meaning the map is hidden, only the Marker of my current position and a dotted line of my route is shown.
Keep in mind I'm a novice developing to Android, so please be specific. (Thank you)
I managed to create the map, get my current position and zoom in to it (Had no sens to see the whole planet while i want only my current position). And it's pretty accurate so far.
The thing is I don't know what should I do from this point on.
Basicly I need a white View between the Marker and the real map. Also as I advance that View should always be on, over the MapFragment/MapView. Also I wish to keep the zoom and drag functionality's of the MapFragment.
How can I achieve this?
At this point I'm opened to any solutions.
(Been browsing for a few days now the developers site, I have seen that with the ViewOverlay class I can put messages over the map, but I'm not sure what would the correct aproach be in my case...)
To hide the whole map behind the white view I would use Polygon class Polygon Even if you specify Polygon to cover the whole map Markers will be still displayed in front of it and as so user's current position marker will be visible. You also will be able to zoom and drag.
To draw line on map use Polyline class Polyline It will draw users path as a polyline. If you want to stick with dotted line you can use Circle objects to create it. Circle

Android Dynamically-Drawn, Clickable Map Overlay?

I'm trying to write an Android app that will allow a user to search for a generic destination (e.g., "gas station") and be presented with up to ~5 nearby locations to choose from. The screen results would display the user location in the center, and possible destination options would be indicated by markers.
The trick is that I don't want to rescale the map from its starting scale, and so some of the possible destinations may not be visible on the screen. I want to dynamically draw a clickable direction indicator (such as an arrow) that emanates from the user location and points to any off-screen destination. If there are multiple off-screen destinations, I'd probably want to scale the arrow lengths to indicate relative distances. If the user clicks on the arrow, they should be "teleported" to the off-screen location.
Any thoughts on how to best implement this? The only information I've found on overlays uses static files (Most overlays seem to be just .PNG files for markers; one example had a route that was drawn from an XML file). I'd need to calculate the arrow based on direction
to the destination (direction the arrow points) and the relative distance to that location (arrow length), so the overlay is something I'd have to come up with at run time.
I think the main challenge is drawing the clickable arrows, but another question that comes to mind is, should I search using the Google Maps API, or is this job more suited to the Google Places API?
Thanks!
I guess we should put the teleportation on hold until the problem of a dynamically-drawn, clickable overlay is solved then!
A dynamically-drawn, clickable overlay is merely a subclass of Overlay. You will override one or both of the draw() methods to render your arrows using the Canvas 2D drawing API. You will override onTap() to be notified of taps on the map, to see if they tapped on an arrow. You add the overlay to the MapView via addOverlays().add().
Most overlays seem to be just .PNG files for markers
Those are usually ItemizedOverlay classes. That's much simpler to implement, particularly if you are one of those developers (like me) who is all thumbs when it comes to Canvas. However, you cannot achieve what you want with an ItemizedOverlay, in all likelihood.
I'd need to calculate the arrow based on direction to the destination (direction the arrow points) and the relative distance to that location (arrow length), so the overlay is something I'd have to come up with at run time.
Correct. You can use a Projection to help convert between pixel space and geo-space (latitude and longitude), if needed.
Note that this all assumes you are trying to use MapActivity and MapView. You are also welcome to use WebView or a plain browser to bring up your own JavaScript-based maps, if you prefer.

I dont want ItemizedOverlay to draw a image on every overlayitem it haver

basically i am trying to draw the path i.e road path. for that i ususally have more then 50 geopoints to link together to draw a path, but the itemized over is also drawing the image on every point, The image that i passed in the constructor. Due to this apart from looking ugly it also slows down my phone. Ite even became hard to move the map too by touching the screen.
so i dont want to draw any image on any geopoint, is it possible or else i should go for Overlay, and a overlay for every couple of geopoint(two geopoints to draw a line between them). I think that would be a overhead for the mobile to manage too many overlays, i.e for 50 geopoints there would be 25 overlays on the map.
That's just what ItemizedOverlay does. Sounds like you need a regular Overlay. Here's an example.

Categories

Resources