Google Maps – Find Nearby Location


To find locations in markers table that are within a certain radius distance of a given latitude/longitude, you can use a SELECT statement based on the Haversine formula. The Haversine formula is used generally for computing great-circle distances between two pairs of coordinates on a sphere. An in-depth mathemetical explanation is given by Wikipedia and a good discussion of the formula as it relates to programming is on Movable Type’s site.Here’s the SQL statement that will find the closest 20 locations that are within a radius of 25 miles to the 37, -122 coordinate. It calculates the distance based on the latitude/longitude of that row and the target latitude/longitude, and then asks for only rows where the distance value is less than 25, orders the whole query by distance, and limits it to 20 results. To search by kilometers instead of miles, replace 3959 with 6371.

SELECT id, ( 3959 * acos( cos( radians(37) ) * cos( radians( lat ) ) * cos( radians( lng ) – radians(-122) ) + sin( radians(37) ) * sin( radians( lat ) ) ) ) AS distance FROM markers HAVING distance < 25 ORDER BY distance LIMIT 0 , 20;

 

 

source:
Advertisements

PHP – Accessing Google Translate with CURL


save the script below to gtproxy.php

change the langpair query string value to your desired value, here I use id (indonesian) to en (english)

langpair=id%7Cen

then test using content as query string to store text which will be translated

eg: gtproxy.php?content=percobaan

<?php

function replace_unicode_escape_sequence($match) {
return mb_convert_encoding(pack(‘H*’, $match[1]), ‘UTF-8’, ‘UCS-2BE’);
}

$query  = trim($_GET[‘content’]);
$query  = urlencode($query);

$ch     = curl_init();
curl_setopt($ch, CURLOPT_URL, “http://www.google.com/uds/Gtranslate?callback=google.language.callbacks.id100&langpair=id%7Cen&key=notsupplied&v=1.0&context=22&q=$query&#8221;);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$contents = curl_exec ($ch);

curl_close ($ch);

$str = preg_replace_callback(‘/\\\\u([0-9a-f]{4})/i’, ‘replace_unicode_escape_sequence’, $contents);

echo substr($str, 57, -19);

?>