Google Maps: Get points contained within a user-drawn polygon? - google-maps

A local real estate agent is wanting to add Google maps to his web site that display his listings. However, rather than just showing map markers to all his properties, he wants the web site visitor to be able to draw an arbitrary polygon on the map, click a button, and then display all his houses within those bounds.
My understanding is that this is going to take some GIS voodoo. But before I start looking into the complexity of PostGIS, I'm wondering if there's a better way to do this? The site runs on a standard LAMP stack, but I'm hoping to convince him to move over to Python/Nginx/PostgreSQL.

I don't think there is a need to move to PostGIS.
First chances are that your client gets the list through an MLS database via an address (123 fooview street). Update that list into a kml file
Using Google maps tutorial or this map tool draw a polygon
using this website (js provided inside the maps) you can do the point in polygon(match if any of your addresses are within polygon boundaries). I think they do it in more than one application.
EDIT
another way of doing point-in-polygon in google maps

I don't think this is going to require as much GIS voodoo as you think. I would approach this in three steps:
Generate a latitude and longitude coordinate for each listing. You may already have this information in your database. If you don't, there are several free tools available to do this. We have programmed a Google maps application at work that links directly to our SQL backend infrastructure that I can help you set up in your application if needed.
Use GLatLng to return coordinates for the arbitrary points the respondent is interested in: http://code.google.com/apis/maps/documentation/javascript/v2/reference.html#GLatLng
Use some math to create an area of the points (will be easier if you only allow 4 points for the arbitrary shape) and then use a for loop to compare each listing's lat/long pair to the area.
If your area is too large to compare all listings to the arbitrary area, do some pre-filtering based on state/county/city/whatever data you have available.
Hope this helps,
-Chase

Related

Google maps - 200K + polygons on the map

I have to plot 200K+ polygons (building shapes) on google map in my project. I have already plotted them on the map. But when moving the map around, it takes sometimes to render polygons. Sometimes even browser tends to freeze. I am looking for either an alternative technique to do that(Something better than Google maps) or a better way to manage polygons.
These are the constraints that I have
** this polygon information is generated on the fly and cannot be pre-prepared.
** Any viewer should be able to see all the polygons(Buildings) in a "bird eye view", so I cant restrict them into a particular zoom level.
You should use some form of server side rendering to generate overlay tiles. We do a similar thing to you with thousands of geospatial objects on a google map. We use the https://carto.com/ service but there are others available and I encourage you to do the research.
Carto stores your data in a postgres database, and then you can use cartodb.js to overlay your rendered data on a map of your choosing (leaflet, google). You can then access click/mouseover events via cartodb.js
https://carto.com/docs/carto-engine/carto-js
I should add that this is easiest for static datasets, but data manipulation on the fly is certainly possible via many of their APIs.

What would be the best Web Mapping API for the following requirements?

I have a fairly simple, and what I would think to be common mapping web mapping project to complete. I'm struggling in my selection of a web mapping API. Thus far, I've not been able to one that meets the following requirements.
Able to display thousands of points in one view without choking crippling the browser. To be specific, I'd say I would like to display roughly 30,000 points at one time and still be able to navigate around a slippy map without degraded performance.
Local maps. The web server will run on the local client, so being able to display a map without reaching out to the internet (even if it's a very basic map) is an absolute requirement.
Render dynamic data from a database onto a map (most API's are meeting this requirement).
Draw polygons directly on the map, and export the lat/lon values of all vertices.
In your experience working with map api's, do any of them meet the requirements above?
I've looked at OpenLayers 3, Leaflet, and Polymaps. Aside from reading every piece of documentation ahead of time, I can't discern if any of these would fill all requirements. Again, I'm hoping someone with experience with any API could point me in the right direction.
Thanks!
As for Leaflet:
Thousands of points: you could use one of these plugins:
Leaflet.markercluster, clusters your points into "groups of points" at low zoom levels.
Leaflet MaskCanvas, replaces all your points by a single canvas layer.
Local maps: as long as you provide a way to create image tiles (even on the local machine), most mapping libraries should work.
Dynamic data: depending on what you call "dynamic", all mapping libraries should provide you with built-in methods to display your data.
Drawing polygons and export lat/lon vertices: use Leaflet.draw plugin
OpenLayers 3 would very probably provide you with all these functionalities as well.

How to implement a (variable!) map into website

i would implement a Map on my Homepage.
It should display a route from a fix start point to a variable end point.
We have a database (mysql) which contain adresses (Street and number).
And thats the only way to determine the two points
I have completely no idea how to do that.
is OSM (OpenStreetMap) a good way to do that? But how can i get coordinates from a adress ...
Yes, OpenStreetMap is one possible way of solving your task.
To embed a map based on OSM you should either stick to Leaflet or OpenLayers. Both offer slightly different features but are easy to use. And both can easily display a GPX file (your route) as an overlay on top of the map.
For calculating this route you can choose from one of the many online routers, offline routers or just stick to a library.
Similarly OSM offers a way to convert an address to coordinates. This is called geocoding and can be done using Nominatim.
Remember to check the usage policies if you decide to use any of the web services (routing, geocoding, tiles). For most of these services there are alternative instances available which are run by different companies and have less-strict usage policies. And of course you can also run your local instances of most of these services if you like.

I need to make a clean, nice-looking map for a presentation based on a Google map. Any easy way to do this?

I want to make a very clean map that only shows relevant information - e.g., only the streets that matter. I was going to just draw a map while looking at Google's, but that turned out to be very slow. Is there any way to make this easier, perhaps with some combination of mapping software and Google's API?
(If I should of put this on another SE site, please tell me)
Building upon Suvi's nice answer.
There is a very useful open-source project that collects street data for the entire globe. It's called OpenStreetMap. On their website you can extract the specific street data you need. It only takes a few clicks and bam! you got the map you need. Their data can also be accessed (perphaps easier for some) from here and here. Those links can provide you with the shapefile(map) that you need. Your newly aquired map can then be loaded in the free QGIS software that was mentioned. There you can easily select the streets you are interested in.
When you mean you want to only show "streets that matter", you are out of luck with using Google Maps. Because you have no control over the ROADMAP data that google provides. Now what you can do, is use another mapping software such as ArcGIS or Quantum GIS (which is free). Both these softwares allow you to load road data shapefiles, and you can query (select) which roads you want to display and customize the look of it to your liking.
If you want a quick approach (without having to download softwares), I believe ArcGIS has an online portal which allows you to display information you want on top of their base maps. You will still need the shapefile for your streets though. Check this link out, make yourself an account and experiment around with it http://www.arcgis.com/home/. If you click on the Map tab, it takes you to a screen which should allow you to upload shapefiles.
You said you were ' going to just draw a map'. If all you need is a very clean map, you can consider using iMap Builder which is a mapping software supports both map shape files, and custom Google maps. I have used to create some simple map projects before and worked great for me. You can use their pre-made map templates which shows just the map outlines without any details, you can then add routes / points / mouse-over speech bubbles etc as you need.

Plot hundreds if not thousands of addresses and do a radius search

In my web application I have a list of businesses/clients and their information, including their address. I'd like to mark one of them, then get the other businesses/clients that are in a X km radius.
I'd prefer to control the X with a slider, and I'd prefer to display the results on a map as well, but neither point is crucial. How should I go about this? Would Google Maps be a good tool? Where can I find more information, or an example of this?
Google Maps API should work well for this.
In fact combine it with Fusion tables, is even better. FT will host your database, and make making 'spatial' queries against your data easy (ie results within X of Y). FT is even intergrated with the Maps API to display the results of your query direct on the map.
If you want to use an Open Source Javascript library with possibly a bit more flexibility than google maps' API, use OpenLayers - and if you dont want to have to pay the new Google Maps API fees, you can use OpenStreetMap for your background layers. Make your slider with something like jQuery UI or Dojo and link them with some event handling. Job done.
What's your back end application written in? There's assorted geospatial libraries that make spatial queries nice n easy in most languages. A bit of googling should bring them up. I doubt you'll need to go for a full spatial database, but if you do then check out PostGIS - that can do stuff like find all the businesses within Xkm of a major road (once you've got all the data into it of course!).
www.osgeo.org is the best start for open source geospatial software. Lots of web, database, and desktop tools there.
Google Maps doesn't support a local search. It provide only an API to find and set marker and get a direction. It has some beautiful maps, too. What you want is the harvesine formula to look for close targets. Alernatively you can use a spatial extension and search for tiles or cluster of targets. It's just an approximation. I don't thin that FT support the former or the latter. It's just a Sqlite-alike database to store your markers.
Try mysql spatial extensions.If you cannot implement Radius Query which i think you cannot consider strongly to switch to postgresql+postgis.Once you migrate this problem will be solved in 5 minutes.
Also for a custom solution take a look at this answer
Cheers