Quadtree on android maps utils - android

I'm developing a android application with google maps v2 that draw polygons on the google maps. But now i have to identify a click on a certain polygon and popup a window.
I found this useful library on github
This library has the method containsLocation implemented. This method receives a LatLng (from click on the map) and a List (the polygon). This is fine but if i have 1 million polygon in the map i cant iterate all and test if a certain LatLng belongs to a certain Polygon. I remember that i can use a quadtree to get more performance and this library also implements a quadtree but it uses point. What is the best way of doing this? May i have to reimplement this quadtree for a quadtree of LatLng ? Or in each click i have to convert this click to a point and search on a point quadtree?
Regards

you cannot use a Point- Quadtree, you need an Object-Quadtree for your Polygons. An object quadree uses the bounding box of the polygon or any object for adding into the tree.
you dont need to consider latLong, use x,y with x= longitude, and y = Latitude.
Consider reading Hanan Sammet: Foundations of multidimensional data structures.

I think you need to implement a quadtree that stores the polygons, then query the tree to see which polygon (if any) contains the LatLng. If you search around I'm sure you can find a decent implementation.

Related

Is it OK to show google map API without actually showing a map?

I would like to use google map API to get a map canvas to put objects on it, but not showing the map, by using the maptype NONE.
Am I allowed to do that in an Android app using v2 and distribute it?
This is what I want to do:
#Override
public void onMapReady(GoogleMap map) {
map.moveCamera(CameraUpdateFactory.newLatLngZoom(
new LatLng(-18.142, 178.431), 2));
// Other supported types include: MAP_TYPE_NORMAL,
// MAP_TYPE_TERRAIN, MAP_TYPE_HYBRID and MAP_TYPE_SATELLITE
map.setMapType(GoogleMap.MAP_TYPE_NONE);
}
I want to set map.setMapType(GoogleMap.MAP_TYPE_NONE); and then add various markers to the map, including my current position
Added a picture to show what I want to achieve.
As mentioned in Google documentation it's forbidden. More over - From what you are saying it seems that you want use gmaps capabilities to get data and calculations but actually display some thing else. I really don't think it's good idea. However - if the issue is making geo calculations, consider to use 3'rd party open source libs for this. For example http://www.gavaghan.org/blog/free-source-code/geodesy-library-vincentys-formula-java/

How to implement google directions API in Android

I'm a beginner in the field of android and currently working on a cab app . In this app I need to implement Map and directions API, I went through couple of tutorials and got several APIs but i dont know how to draw the returned data on the map so guys please help.. need some guidance. Thank you
For the moment i've extracted the latlng of source and destination and have created a seperate MapActivity for showing directions.
Google Directions API gives you a polyline (a list of LatLng points to draw a nice curvy line) of the returned route in an encoded format in "overview_polyline" and "polyline" fields in the JSON it returns.
By decoding this data you can create a Polyline object which is then drawn on the GoogleMap. Writing your own decoder isn't too difficult, but there's also android-maps-utils library that contains a method for this and many other fancy things you might want to use on Google Maps related things.
An example use of this library would be something like
GoogleMap map = ...;
String encodedPolyline = readFromJson();
Polyline line = map.addPolyline(new PolylineOptions()
.addAll(PolyUtil.decode(encodedPolyline))
.width(5)
.color(Color.RED));

Using polygon class in google maps without having maps view

I am developing an Android application where I need to check whether a GPS point lie inside a region (or polygon). I am therefore planning to use Polygon class provided by Google Maps. But, this require a map view to construct a polygon. I don't want to use a map view. Kindly tell if there is a class or some API by which polygon can be used. I have come to know of a PolyUtil class but it requires importing another library.
Thanks,
Arpit
Use this lib android-maps-utils:
PolyUtil.containsLocation(LatLng point, java.util.List<LatLng> polygon, boolean geodesic)

Is there a better way to do this? Plotting lots of map markers

I'm working on an android app.
I'm basically plotting a set of data to a map. They are camera locations. The map will shown a customised marker icon at the location, as well as contain a snippet of information when you click it.
I've a LOT of data to plot. It is Lat/Long coordinates.
I've just created an xml map fragment, id'd it, and dumped this into the MainActivity.
If you just want to avoid having a lot of similar variables, use a Collection. I tend to use ArrayLists.
This is how I would address your situation:
ArrayList<LatLng> cameraLatLngs = new ArrayList<LatLng>();
// You should use a loop to add the LatLngs to the ArrayList
cameraLatLngs.add(new LatLng(51.6167, -3.9500));
cameraLatLngs.add(new LatLng(51.581, -3.9550));
for (int i = 0; i < cameraLatLngs.size(); i++) {
map.addMarker(new MarkerOptions().title("camera" + i)
.icon(BitmapDescriptorFactory.fromResource(R.drawable.cctv))
.snippet("<Camera Details>.").position(cameraLatLngs.get(0)));
I hope that answers your question!
One time I tried creating markers for all the bus stops in my city... all 2,200 of them. Needless to say, my phone would stumble a bit when I tried to pan around. And when I zoomed out, the markers completely obscured the map.
I haven't had a chance to apply this solution yet, but if I ever revisit my bus app, I'll probably use tile overlays. You can provide different levels of detail at different zoom levels. You could also detect map clicks near your camera locations to display your details.

Add 1000's Markers to android Googlemap

I am developing a GoogleMap based android application.
I need to display 1000's of Markers on the map.
Currently I retrieve the Latitude and Longitude for each marker from an SQLite database loader and add the markers in the public void onLoadFinished(final Loader loader, final Cursor cursor) method.
this approach gives a very bad user experience though, as the application does not respond while i add the Markers.
how can i add 1000's of markers to a googlemap and keep my application responsive?
as i have to add the markers to the map on the main UI thread.
One possible way is to only add Markers when they fall into visible region of the map.
You would actually have to move your calls to addMarker from onLoadFinished to onCameraChange and in onLoadFinished only create a list of data needed to create these Markers. In the simplest form this might be List<MarkerOptions>.
Android Maps Extensions mentioned by Lalit Poptani in the comments above can handle that for you even if you don't want to use clustering. You simply leave your code like it is and only make a call like
googleMap.setClustering(new ClusteringSettings().enabled(false).addMarkersDynamically(true));
after replacing Google Maps Android API v2 with this extensions lib.
You can use Spatial Lite provider with geoserver to provide WMS maps.
In android you can set a tile provider to consuming such tile maps.

Categories

Resources