Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Finding a dealer area via google maps API [closed]

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.


1 Answers

  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.

like image 137
nshaw Avatar answered Dec 07 '25 00:12

nshaw



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!