/* use the following snippet to geocode addresses and work out if an address is within a polygon or line of sight distances requires your own Google Maps Platform API key https://cloud.google.com/maps-platform/pricing */ $GOOGLE_API_KEY = 'xxxxxxxxxxxxxxxxxxxx'; $gg = new GoogleGeocodingAPI($GOOGLE_API_KEY); $gg->setDestination($DATA['destination']['address1'],'',$DATA['destination']['city'],$DATA['destination']['province'],$DATA['destination']['postal_code'],$DATA['destination']['country']); $customerLocation = $gg->getLocation(); //see if customer is within polygon //format: [[lat,long],[lat,long],[lat,long]] $polygon = [[38.1481562,-123.0240327],[38.4667462,-121.9805727],[37.6923902,-120.6537037],[36.9998603,-121.5998587],[37.5374152,-122.4660557]]; if (pointInPolygon([$customerLocation['lat'],$customerLocation['lng']],$polygon)) { //customer within polygon } else { //customer outside polygon } //calculate distance between a co-ordinate and the customer $point = ['lat'=>36.9998603,'lng'=>-121.5998587]; $d = $gg->getDistance($customerLocation,$point); print_r($d); /* sample output: Array ( [meters] => 2517215.7349647 [kilometers] => 2517.2157349647 [feet] => 8258582.0719016 [yards] => 2752859.8515619 [miles] => 1564.1253423536 ) */