/ Published in: PHP
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<? # this snippet can be used to see if $postcode is within $radius of $shop_long $shop_lat $shop_long = 'LONGITUDE GOES HERE'; $shop_lat = 'LATITUDE GOES HERE'; $key = "GOOGLE_MAPS_API_KEY_GOES_HERE"; $stlen = ($len == 7) ? 4 : 3; $postcode = $start.' '.$end; } $postcode = $postcode." UK"; # hack for UK postcodes to work properly :( $xml = new SimpleXMLElement($page); ?> <h1>User Coordinates:</h1> <ul> <li>Longitude:<?=$customer_longitude?></li> <li>Latitude :<?=$customer_latitude?></li> </ul> <? $shop_longitude = (float) $shop_long; $shop_latitude = (float) $shop_lat; ?> <h1>Shop Coordinates:</h1> <ul> <li>Longitude:<?=$shop_longitude?></li> <li>Latitude :<?=$shop_latitude?></li> </ul> <? $radius = $radius; // in miles $lat_min = $shop_latitude - ($radius / 69); $lat_max = $shop_latitude + ($radius / 69); $yn =((($customer_longitude >= $lng_min) && ($customer_longitude <= $lng_max)) && (($customer_latitude >= $lat_min) && ($customer_latitude <= $lat_max))) ? 'yes!':'nope!'; ?><h1>Within <?=$radius?> miles ? <?=$yn?></h1>