I have imported Osmdroid 4.3 into my application, but I have problem while tapping on displayed overlays. After I have moved over the map, I have to double tap overlay to display what I want, then, when I tap anotehr overlay, it just needs single tap (= the right way, app is programmed).
Question is, anyone faced same problem with newest osmdroid while taping on the objects on the map? Or is there anything changed from my previous version 3.0.8?
Thx
Edit:
Osmdroid 3.0.8 - I can pan map, go through the map, left, right, top, down. I have displayed POIs on the map. I can double to tap to zoom, pinchzoom to zoom-in or zoom-out. I click on POI, then I have all vailable details about POI displayed.
Osmdroid 4.3 - I can pan map, go through same as before. The only difference is, when I tap on POI item, map does nothing. Then, If I tap on the point again or I want to pan map doesn't matter. Both gestures are now the same and I see displayed POI details. When adding POIs to the map, I am using my custom class which extends OverlayItem. Why it needs double tab? Why is seems to me, that displayed OverlayItems are now "separated" from the map? Because first touch on them seems I have to "active them first", and with another touch (no matter what kind of touch is is) finish my work and display POI details.
I have done no change to the source code, only swapped the libraries. What am I doing wrong?
EDIT2:
I think I have found the change between osmdroid 3.0.8 and 4.3. In my App I am evaluating which POI was clicked by OnItemGestureListener and its method onItemSingleTap. In OnTouchEvent I am displaying POI details. In Osmdroid 3.0.8, while tap on POI, there was call hierarchy 1) onItemSingleTap 2)onTouchEvent. In osmdorid 4.3, their calls are switched, so 1)OnTouchEvent 2)OnItemSingleTap, so my first touch generates nothing.
I think I have found the change between osmdroid 3.0.8 and 4.3. In my App I am evaluating which POI was clicked by OnItemGestureListener and its method onItemSingleTap. In OnTouchEvent I am displaying POI details. In Osmdroid 3.0.8, while tap on POI, there was call hierarchy 1) onItemSingleTap 2)onTouchEvent. In osmdorid 4.3, their calls are switched, so 1)OnTouchEvent 2)OnItemSingleTap, so my first touch generates nothing.
Solution to this is: in onTouchEvent I get IGeoLocation from place I touch my finger. Then I look up the database and find all POIs with coordinates around my touch with distance lower then threshold. This threshold (e.g. +-0,010 lat and +-0,10 lon) must be set for each zoom differently. E.g. when having zoom 16, threshold is 0,001 (when click on 1 POI only, I don't want to see selection of distant points), when having zoom 12, I set threshold on 0,125, so my finger selects only some POIs which are together and not the whole map. So If you have ability in your app to touch multiple POIs, be aware of this change in Osmdroid 4.3.
Related
I am building an application which uses Google Maps. When displaying the map, I'm also adding markers. Is there a way to see if there are 2 markers that touch each other, meaning if a part of a marker is on top of another marker? My goal is to be able to find that out and then make them a single bigger marker instead of 2 different markers.
The answer should depend somehow on the marker's icon size and the current map zoom since if I zoom out, there's a bigger chance they might overlap.
There seem to be a library made by Google which clusters a set of markers together automatically when they are close to one another.
The library is the marker clustering utility and instruction can be found here:
https://developers.google.com/maps/documentation/android-api/utility/marker-clustering
I am developing an android application using Google maps with clustering of markers. The application works fine however once you zoom into a specific area and all the clusters expand to individual markers I would like to also show a small view that represents the entire map, where you are, and where all the markers are, to enable the user to navigate round the map while zoomed in. Ive Googled and searched SO, but not found anything. Is there any "off the shelf" solution? Or am I going to have to code this all myself? The type of solution I am looking for is the type of small window that many games use to show an overview of where the player is and all the points of interest are within the current level.
I haven't seen any "off the shelf" solutions, but here is what I would do here:
1) Create an additional fragment of the map. Place it in one of corners like games do
2) Here is where all the magic should happen. You need to synchronize these 2 maps. Map's Projection lets you to translate geo coordinates into XY coordinates within the view. That's being said you can get lat/lng of your top-left and bottom-right corners on the main map and translate these 2 corners into top-left and bottom-right XY coordinates of the mini-map's view. Now, when you have XY coordinates, the only thing you need to do - is to draw a rect on top of the mini map.
There is even easier and more native solution - since you have top-left and bottom-right lat/lng coordinates - you can draw a set of polylines on a minimap to get a rect. But in this case it will be hard to move it around (with your finger) in case you want to change current main map location using mini-map
I'm implementing a feature in my app that allows user to manually locate themselves on a map. So I use a pin to represent their location and let user drag it to the place they currently are. The simple solution is to use setDraggable(true) on the marker, but this requires users to hold the marker for 3 or 5 seconds until it is draggable. I think this is quite confusing for many user to use the feature. So, what I want is to make the dragging more responsive by letting users drag them immediately without having to hold it for a while - like how Foursquare does!
What should I do to implement my own dragging feature? If you have any suggestions, please help me and thanks.
Check out the Hailo application. They have a neat workaround for this. It only works when you have one marker to drag.
The trick is to pan the map, instead of moving the marker. They just keep the marker in a view on top of the MapFragment (it's not actually a Marker on the map).
You can then use the map's cameraPosition.target as the location of your marker.
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 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)