Google Maps Android - set too many markers - google-maps

My question is, What is the best way to set to many markers on google maps on android program? I have a sqlite database with longitude and latitude for every markers.
For example add all markers 1km around the current location
Get the range of longitude and latitude on moving map and display markers between that range
How can i get the range of longitude and latitude?

Based on the comments from above you will need to do the following:
1) Use the Google Api maps reference for Android to determine the visible area on the map and if one of your points is within the determined area.
2) Carefully remove points added to the map but which are no longer needed. (IE the user has moved the map). Be careful at this point not to remove a point before the map has finished updating, as the user could tap on a point and crash the app.
3) Decide what you're doing about zoom level, if a user zooms right out then you need to do one of the following:
a) Display nothing, give the user feedback to zoom in for points.
b) Use an algorithm to plot a point at an average of a point.
c) Display a marker as with b but centered in a region with the number of points in that region.
I would advise lots of research on stack regarding previous questions as this topic has been covered in some detail.
For c) there has been a good iOS implementation which is now a for-sale library, however the name of the library escapes me at the moment. I am told the implementation is excellent.
I cannot express enough that you need to make sure your map operations are done asynchronously, be wary of this or fall into lots of traps.

Related

How to use Google Maps projection with GeoDjango/PostGIS

I am building a web service with GeoDjango which involves user submitted events including a location. I created a model field for my location using django.contrib.gis.db:
location = models.PointField(srid=900913)
I chose to specify 900913 as I read that this is the projection used by Google Maps and I am getting the location by placing a marker on a Google map. The coordinate is presented to me in lat/lng form. I am storing this point in a PostGIS DB using GEOS:
location = geos.Point(data['lng'], data['lat'], srid=900913)
If I want to view this point on a map, I get the lat and lng from my DB (e.g. lat = location.coords[1]) and use them to centre my map and this works fine.
When I want to browse a map and display events from DB which lie inside the map bounds I use GeoDjango's within query and the maps bounds (in lat/lng format):
bounds = geos.Polygon.from_bbox((swLng, swLat, neLng, neLat))
events = Event.objects.filter(location__within=bounds)
This appears to work fine and I display pins on the map corresponding to the lat/lng of these events.
So far nothing would suggest that anything is going wrong, however I am completely new to this stuff and I want to ensure that I'm getting it right for when I inevitably want to use my location data in more complex ways. The reason I'm suspicious is that my Django admin pane does not display the location correctly on the OpenStreetMap. It shows a point which appears to correspond to the (0,0) point shown here. The displayed text version of the location field is SRID=900913;POINT(-1.277482509613037 50.874104373286066), which is clearly still in lat/lng. As I move my mouse around the admin map I can see the displayed coords in the bottom right corner are in 900913 format, and not in lat/lng.
Please can you explain how I can store my location points in the correct format, and what advantages this has over simply using lat/lng (my guess is that if I want to specify say a distance in km for lookups, I can't use my lat/lng locations).

Set location on google map

I have created one small application, where user can store his/her contacts with full address including map. Therefore I am using the Google Maps API, where user can point out his/her address.
For this I have given address fields with Country, State and City. When user entered this information, I am showing the default address on Google Maps, then the user has to drag the marker/pointer onto his/her exact location.
Now, in this case I want the zoom level of googles map to be set as per location's population.
This means if the user entered city with no mans land (less population or any desert place or any jungle place or very small area on city then zoom level should be more, so user can see proper area on map) otherwise zoom level should be less.
Can some one guide me how to do this?
This won't be possible using the Google API's alone, (I'm unsure if demographics info has been released for the US, I know it was in the works, but it certainly won't work elsewhere). You will have to find an external source to provide your demographics information for you.
The Google API's do not keep a public record of population density.
You could however be a but more tricksy and use an approximation. You could for example do a places search in the area (using an arbitrary radius), count the number of results and use this to set your zoom level (again using an arbitrary value to determine high/medium/low etc). It's a fair assumption (though still an assumption) that any area with a large number of 'places' returned will be densely populated.
You don't need to base this on the population of the location. Please check the follwing link. I think it should give you an idea of the options you have.
Google Maps API v3 - Geocoder results issue with bounds
Check both my question and my answer. You will probably want to use the viewport object.

Real-Time update of markers in google maps?

thats my scenario: I want to load a list of places of interest of a user based on his location (using HTML5 geolocation). But the problem is, I have a very big list of places (I don't want to have to load all places from my database), so the solution I have adopted until now is only to call mysql for the results in a given radius from the user, let's say, 1 km. But I'd like when user is dragging google maps to explore the map, load progressively the places for the area is shown on the map (basically something similar to what foursquare does).
Is there any simple way to achieve that? Hope I was clear with the question, thanks in advance, any help is appreciated.
Jesús.
General approach:
get the bounds of the map and query your data base for markers that are currently in view
optional, add padding to the bounds so some markers are available just out of view if the map is dragged
display the resulting markers
when the map is moved (bounds_changed event), query your database for additional markers
process through the returned markers, only adding those that are new (requires an array of existing markers and a way to determine that the existing marker and a newly downloaded marker are the same)
Searching the Google Maps API v3 group (and the Google Maps API v2 group, the concepts will apply but the code samples may not) should give you some examples.

How to compare Google Maps coordinates on an accurate way?

I have the coordinates(lat, lng) and the information associated to this point in an excel sheet.
I want to compare the coordinates that I have stored on a database(lat, lng) with the excel ones.
My main idea is to show the correct info about the road point on the info window associated to the marker.
My doubt is about how to choose the coordinates on the most accurate way?.
Any suggestion?
So I think I understand what you are doing - capturing the coordinates of a user's location and then you want to find information about what is nearby to that location. If I have that correct, I suggest you take a look at the Places Library.
Google provides a library/service that allows you to send a requestthat includes a location and radius or coordinates that define a rectangular bounds and the service will return information about nearby places of interest. There are many ways to refine the searches to focus on different types of features.
I think this is what you are looking for - if not, provide a little more detail and I will try to help you.

Plot coordinates near a given set of coordinates on Google maps

This is the scenario...
I have a set of lat/long data stored in a db table[id, lat, long, location]. I'm using geo-location to get a user's current physical location(lat and long). When this user accesses the app, allows his location to be shared, I want to get those coordinates that are around his current coordinates, and plot them on a Google Map.
How can this be done?
Example: I have the coordinates for hotels in a city stored in my DB table. When a user visits this city and accesses my app, I want to get from my DB and plot on map only those coordinates that are around him in a certain radius.
Note: I'm using PHP for server side stuff.
Any help is appreciated!
You describe a store locator: finding POIs within a radius around a particular point. A store locator finds POIs within a radius around a location. The details in Google's example are different (you find the centre point via browser geolocation and have a fairly small radius) but the principle is exactly the same.
Google's article: developers.google.com/maps/articles/phpsqlajax_v3