Alert when current location is near marker android map - android

I am building an app for android that uses google map. its like a navigation app that updates the location on screen while in motion. I have placed multiple markers on the map and for each marker there is a radius of 125. When the current location intersects with the marker radius I get a warning message. This is done by looping through all markers and check if the current location intersect with the radius of any of the markers at the OnLocationChangedMethod() . it works well if you have couple of markers but I have more than 30 markers. By the time it takes to loop through all markers and report if there is an intersection , current location would have passed the marker. so it takes longer time and its not very efficient.
I hope someone can help for a better approach on how to do that. I have read couple of solutions that suggest taking the map bounds and find the visible marker. but this also iterate through all marker and it would take the same time as my solution.
I would appreciate if anyone could help.
Thanks,
Abdullah

This sounds like you would be better suited for Geofencing because it is basically what you are trying to do. No need for all these different services and such when there is something already built in

Use two services. One to get the current location and another to calculate the distances.

Related

Google Map V2 Lib Android, draw active path from GPS update

I don't want to show the route as there is no destination point in our app, so what we want is to show the active path of the user over the map from the starting point to the current point.
Problem: As some time or most of the time the location shown outside the road on which user is traveling, which draws the path outside the roads.
Help me to draw the path on the road as user is driving on the road.
How Google do the same? or is there a way to do so which i am missing or
any algo to correct the path.
That is a very common problem that all GPS devices need to solve.
See http://econym.org.uk/gmap/snap.htm for some examples to snap your location coordinates to a street.

Make my own "Google Maps" using device location

Im on my final project in which I would like to build an android app especifically for the university context. Therefore I would like to use geolocation but for matters of detailed information (colors, shapes, buildings, etc) and gamefication I would like to draw my own map and the user should be able to see his position on this map. So I would have this drawn map and I would use the device's location service and transform the coordinates to a position on my map.
I'm kinda lost on this, didn't find much on the web. So I would apreciate if anyone could point me a direction or if anyone could tell me how hard would it be to implement. Would it be as simple as a function Point foo (double lat, double lon);?
Thanks in advance.
Drawing the whole map completely would be rather difficult and would involve loads of extra work, thus I would suggest you an alternative that would allow you to have your own drawings, on top of the already made Map.
You could for example use the groundoverlay, for items that you want to draw yourself. and then use the google maps under it to show the map, and to handle any positioning etc.

Google maps api v2 how to find the nearest location

I am using Google maps api v2 in android. I have created xml parser for the bus stop. Bus stops are displayed using markers. I need to find the user's current location and find the nearest location (bus stop), best automatically (for example in a radius of 0.5 kilometer).
I tried to find a tutorial, but unfortunately I failed it.
Thank you for your help.
There is the distanceTo() method of Location class that gets the distance between 2 locations, in a straight line. You can find an example on how to use this here: How to get straight distance between two location in android?
But, if you don't want the straight line distance, rather the Travel distance, I'd recommend you take a look at this question and answer: Get the distance between two locations in android?

Dynamic geofence and google maps Android app

I am asking advice on the best way to create a geofence application for android application using google maps.
I have looked at the sample code given on the android documentation but I am not sure if this satisfys what I wish to do. Basically I wish to show the user location and a radius and alert if the user goes outside this radius. The size of the radius is dynamic and can be dependant upon the time of day.
Could anyone give me any good starting points on what I should be looking at please? I know this is a general question but I am seeking advice on the best way to achieve this not for someone to supply code and give me it.
Thank you
User location can be obtained using GPS and as you said radius is dynamic and is dependent on time, so radius can be figured out from time. Now you have user location and radius. Now, you can calculate distance of user location from center of circular geofence and then compare it with radius.
Distance calculation between two points over map can be done using API like "distanceTo" available in developer website. http://developer.android.com/reference/android/location/Location.html
If radius is bigger than distance, user is inside the geofence and if radius is smaller than calculated distance, then user is outside of dynamic geofence.
For more info regarding implementation- visit
http://developer.android.com/training/location/geofencing.html

Google Maps Android API v2 routes json parsing

Hi With the help of LocationManager I managed to find current location in android.
For showing routes between two geo- co-ordinates what should I use so that I wont plot air distance instead will show ground routes or is it with help of json can I plot routes.
I have tried polyLine() but it gives straight line.
To work out the line between two points you need to know what map projection type you are using. Some map projections preserve shape (and therefore angles) others do not. Take a look at http://www.progonos.com/furuti/MapProj/Dither/CartProp/ShapePres/shapePres.html it might help.
If you're using a Mercator projection then I found this page that claims an algorithm in C# that should point you on your way: http://conceptdev.blogspot.co.uk/2009/01/great-circles.html
As for the line segments, ployline will give stright lines between the points. You'll need to use Path and use the Bézier curve methods Path.cubicTo() and Path.rCubicTo() from memory.
Do you have all permission set in the Manifest? Also, you have to enable the location service (is the gps icon in the status bar showing?). It'll take some time for the device to get the location, so see if onLocationChanged is called.
Here you can find the answer for your qustion:
Is there a way to show road directions in Google Map API v2?
and here:
Get driving directions using Google Maps API v2
basically what you should do is make a call to Google Directions API receive the road direction coordinates (many Latlng points), and then draw a polyline between each one of them.

Categories

Resources