views:

42

answers:

2

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.

+1  A: 

I don't think this is going to require as much GIS voodoo as you think. I would approach this in three steps:

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

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

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

Chase
+1  A: 

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

dassouki
Thank you. The term "point in polygon" is what I needed to research to accomplish this.
jamieb