Googlemaps search with mongodb geospatial best strategy - google-maps

I have a website where people can view some places on a google map, which are stored with a lat/lng coordinate. The storage is mongodb. Now when the user navigates the map, I need to lookup up which places now are in the visible part of the map.
I'm new to mongo, but have looked at the spatial part. My question is now an effective way to do this lookup.
Do I need to make a ensureIndex each time the user navigates the map, and how do I then query all places within the visible boundaries of the map?

According to the mongo docs, you can query within a bounding box like so
box = [[40.73083, -73.99756], [40.741404, -73.988135]]
db.places.find({"loc" : {"$within" : {"$box" : box}}})
The key point here is the use of within to query within a bounding box.
In order to get the values for your box, just get the bounds of the google map like so
map.getBounds()
Where map is your google maps object. getBounds will return a LatLngBounds object from which you can build your box to query mongo.
As for ensureIndex, you should do that once as far as I know.

Related

What does Xamarin.Forms.Map display?

I used this Xamarin.Forms Map tutorial to create a simple app that displays a map and plots several points (from our database). The app works as it should, and that would normally be enough.
But I wanted to make my app different, and I wanted to use another type of map. For example, Waze and Google Maps both show me how to get to my nearest Walmart, but I like Waze's map more.
So my question is: what exactly does Xamarin.Forms.Maps display? It's a control that shows a map, but why does it show a Google Map instead of, say, a MapBox?
And since Google Maps and Waze are owned by the same company, why wouldn't I be able to display the Waze map instead of the Google Map?
Finally, what other map control options do I have? My app simply takes several coordinates from a sql table and plot the points in the map.

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).

Google Maps Search: Center map on search results markers

I have a Google Map (v3) setup with search functionality to search a Fusion Table. The search works fine, but I need for the map to center on the search results marker(s). I have a large field of markers and would like for the user to see all of the search results in one screen.
Thank you!
Use the Fusion Tables v1.0 API or GViz to query the table. Add all the locations to a google.maps.LatLngBounds object (with extend). Call the .fitBounds method of your map object on the resulting bounds. Need more information to give more details than that.
Examples querying tables with various data formats on geocodezip.com

Google or Bing maps API - creating and using your own map

What I need is the following.
Whenever I add any instance of object in my website, I need the server to add the location of the object to my own map either in Google maps or Bing maps (Bing maps docs are more clear therefore I'm going to use Bing).
Later, whenever I view the object in my site, the map should point to the location of the object and other my map objects in the same map.
How can this be achieved? Do I need to hold all the coordinates and object descriptions in my server, or somehow it is saved in the google or bing.
I went through the docs, but couldn't find any information I need.
You need to store them on your server and load them into the map on your webpage. There are ways with both google (fusion tables) and bing (spatial data services) of storing them with the provider but if you are already storing a copy for your website you are better off keeping them there for the map rather than maintaining two copies.
I'm not sure how technical you are but this best architecture approach is this:
1) Write a database query that finds objects to show on your map, ideally filtered by whatever the user can use to filter objects elsewhere on your site. Add to this query a filter by geographical bounding box (the range of latitude and longitude that can be seen on your map at any one point). The bounding box filter is just a simple sql BETWEEN clause but will mean you dont have to load every single object on to the map.
2) write a "webservice" that uses the database query in 1) and turns the results into JSON. This approach will lead to a much cleaner seperation between your mapping code in javascript and your server side code in the webservice.
3) Write your mapping frontend in Bing using javascript and use something like Jquery to read data from the webservice as the map is moved around re-load data that know should be shown on the new map view. As the data will be in JSON its much easier as JSON will just give you javascript versions of your objects

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.