Ok, Hello everyone (sorry for my English). I have a task to make some good location service. I use google and stackoverflow , find a lot of tutorials, but i want to ask am i right? I have destination point and my current geo position. I draw route like this tutorial http://iamvijayakumar.blogspot.com/2013/04/android-draw-route-between-two-geo.html, and now i want to react if my current position changed, so i implement OnMyLoactionChangeListner, and now the question: if my position change i have to get new rout from url and redraw my polyline, or i can just make a marker and mark my new position above the old route polyline? what decision is right? Thanks for all
I think that best would be to check if your current position is on the old route. If so, you could just shorten the first polyline. But if the position is outside of the route, you have to recalculate it.
Related
Let's say I've a lot of makers I made all over the map.
But when I click a button, I want to show only markers from a radius(1km) of my current location and dismiss everything else. Is that possible?
I just don't want to pull every markers from SQLite and validate them if they are containing within 1km or not because validating millions markers will lower the app performance I thought. So, I wanted to do only in the view layer if possible.
I think you can't do it from the view layer.
All solutions will have full iteration over all marker's set.
Much better will be get them from sqlite by specific query.
Something like:
select * from markers
where lat between 35.45 and 35.46
and lng between 55.11 and 55.13
Of course, this will find square region, but you understand the idea.
And with proper indexes it will be much better than all markers check.
Anyway if you find any solution post it here please.
Yes of course that is entirely possible. A possible solution is to go through your array of markers and calculate the distance from your current location to the marker, when your button is pressed. If it is greater than 1km, then set the marker to be false like so:
marker.setVisible(false);
See this webpage for an example of hiding a marker on click (the principle is the same, but you'll have to tweak the logic a little bit): http://googlemapapitutorial.com/hidemarker.jsp
You can check for the visible area like this
private VisibleArea getVisibleRegion() {
if(mMap!=null){
VisibleRegion region = mMap.getProjection().getVisibleRegion();
LatLngBounds bounds = region.latLngBounds;
VisibleArea visibleArea = new VisibleArea(bounds.northeast.latitude, bounds.northeast.longitude, bounds.southwest.latitude, bounds.southwest.longitude);
return visibleArea;}
return null;
}
Now add the markers only in this area and remove rest of the markers from the array by this way it will be much faster..
I'm using Google Maps on Android, and I have a marker as an overlay in my MapView. My question is, how do I get the latitude/longitude corresponding to the position of my marker on the map?
I just added a class-level variable and used it to keep track of the marker position as it changed, and queried that when I wanted the value. If someone has a better answer, please post it; otherwise I'm assuming this is the best way to go.
I’m looking to force Google direction service to zoom to the final destination rather than show the entire route. Is this possible? If so how would you go about doing this? I would also like to remove the markers I set once the start and end locations have been set and the calculate route function is called is this possible? I don’t think any of the code will help it’s done in v3. I have been searching and found nothing related to the zoom issue. Can anyone please help…
Well this did help, now looking at it hough, i think maybe should have add my code. i'm going to try it in here first. I would like the "A" & "B" markers to stay i have built arrays for othere markers that i would like to suppress once the calculateroute function is handeld or have a button that turns them on and off that wont clear the map or add additional turn by turn directions.
First pass these options when intializing the directionsRenderer:
{suppressMarkers:true,preserveViewport:true}
...so you will not get markers and the map will not fit to the bounds of the route when rendering.
Then, after rendering the route( setDirections() ), call this:
directionsDisplay.setDirections(response);
//set the center of the map to the end of the route
map.setCenter(response.routes[0].legs[response.routes[0].legs.length-1].end_location);
//set the zoom to the desired value
(where directionsDisplay is the directionsRenderer-instance)
I'd like to dynamically update the map/ load new map overlays every time my user moves it a certain amount of distance. How do I go about doing this? Is there a listener for every time the user moves the map? Most likely I'd just measure the distance between the center points.
Thanks!
Try this to detect the map movements:
http://pa.rezendi.com/2010/03/responding-to-zooms-and-pans-in.html
On start and after the map has been moved, you should save the current map center. As the article suggests, track ACTION_UP to determine when the user has finished a map movement. Then, compare the new map center with the old map center. To get the map centers use MapView's getMapCenter():
http://code.google.com/android/add-ons/google-apis/reference/com/google/android/maps/MapView.html#getMapCenter()
EDIT: I have done some additional work on this, and have a complete application with code for your enjoyment. This blog post explains a timer solution to this and contains a link to Github source:
http://bricolsoftconsulting.com/extending-mapview-to-add-a-change-event/
The map interface unfortunately does not include any listeners to monitor map actions (zoom/pan). You'll need to set up a timer of some sort that checks the center/zoom levesl to figure out if things have changed and update accordingly.
You could do this by overriding the onTouch(...) method in your Activity (so that every time the user pans the map, you could recalculate the map boundaries). You would need to know the map's zoom level and boundaries, etc, in order to load these overlays based on map distances.
I am having an app which tracks the Geopoints of the user. I simply fetch these points and use them to draw the path on Map View.
My issue is, when I see the path tracked by user, the path seems to be correctly plotted but, when I have a first look over the map,it does not show me an entire zoomed out view of the map where I can see all the track path. Instead the map begins with from where I started tracking and then I need to scroll all my way to see the further tracks.
Please Help. :)
Thanks In Advance.
Use MapController.zoomToSpan(...), you can get the span from your ItemizedOverlay methods getLatSpan(int) and getLonSpan(int). zoomToSpan(...) is a best effort method and does not guarantee that all points will be visible.