views:

802

answers:

3

I have a national customer who are currently recruiting dealers by selling each dealer an area for a set fee. They want a 'find a dealer' feature on their website which should point customers to the dealer who has purchased the area the visitor enters. At first we were going to list major cities with the hope that the visitor would click on the nearest city name that they recognised, but it occurred to me that it must be possible to use the maps API to map postcodes or town names to specific areas.

The problem is that it's not quite a "find my nearest dealer" scenario because of the way they're selling specific areas - the dealer for your area might not be the nearest to your postcode/town. I've used the Google maps API in the past, but mainly for plotting things on maps dynamically rather than using it to calculate some geography for help in a database query - can anyone help? I'll be using the PHP API if that makes any difference.

A: 

It sounds like you will need polygon regions that represent the dealer's specific area. You can make polygons with the Google Maps API and then you should be able to let user click or mouse over those...

Jared Updike
Thanks for your answer. The problem is that we're covering the whole of the UK with several hundred small dealer areas so I don't think a clickable map would be practical. What I was hoping was that I could use the API to translate the postcode/town entered to a dealer area from my database.
A: 

Urbanware has a neighbourhood API, maybe that's something you can use? I'm not sure if it's free (since they offer premium as well and I haven't read their TOS) but since this sounds like a commercial project anyway, you might be able to justify the cost.

EDIT: Just noticed that only premium gets access to the European databases, so it sounds like you need that anyway.

Till
+3  A: 
  1. Create your polygons in Google Maps using KML or whatever format you have them in.

  2. Use Google Maps to geocode the location that the user enters (in other words, transform postal code and city to lat/long).

  3. Use the contains or containsLatLng methods of the GLatLngBounds object in each polygon to determine whether the lat/long is within one of the polygons.

nshaw
This sounds like exactly what I need! Thanks!
Your advice sounds spot on but some simple examples would make this answer worthy of a reference for future devs.
TravisO