[eluser]yannyannyann[/eluser]
Thanks Joe.
I started converting to a controler... might help you :
Code:
[removed]
<?php
$zoom_lvl = 5; ?>
var url = '<?php echo URL ?>map/index/MY_API_KEY_HERE/MY_ADDRESS_HERE';
console.log(url);
$.get(url, function(data) {
var json = eval("(" + data + ")");
if (json.coordinates.lat != 0) {
$('#map').jmap({ center: [json.coordinates.lat, json.coordinates.lng], zoom: <?=$zoom_lvl?> });
}
});
[removed]
Code:
<?php
class Map extends Controller {
function Map()
{
parent::Controller();
}
function index($key, $address)
{
// this is a very unelegant method of getting map markers
// but it works for the moment - until more than 10000 happen in one day
header('Cache-Control: no-cache');
header('Pragma: no-cache');
// build the google url to ping for coordinates
$address = str_replace(' ', '+', $address);
$url="http://maps.google.com/maps/geo?q=" . str_replace(" ", "+", $address) . "&output=csv&key;=" . $key;
// send the request
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt ($curl, CURLOPT_RETURNTRANSFER, 1);
$remote_content = curl_exec($curl);
curl_close ($curl);
// scrape the returned csv
$coordinates = split(',', $remote_content);
$lat = $coordinates[2];
$lng = $coordinates[3];
// return some json
$data = '
{"coordinates":
{
"lat": "' . $lat . '",
"lng": "' . $lng . '",
"address": "' . str_replace('+', ' ', $address) . '"
}
}';
echo $data;
}
}