How to automatically populate user coordinates (Lattitude / Longtitude) to the FORM based on a user location ?
Arthur
How to automatically populate user coordinates (Lattitude / Longtitude) to the FORM based on a user location ?
Arthur
Mmm this is something similar as the other question. I use the googlemap api for that.
ok, so how you connect Google API with SC ?
The following code is old, it might be that the api has been changed a little (V2->V3), but all docs are on google, so I hope this helps you on the way.
$key = "";
$uei=$row['user_extended_id'];
$address = urlencode($row['user_postcode']);
$url = "http://maps.google.com/maps/api/geocode/json?address=".$address."&sensor=false";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER,0);
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER["HTTP_USER_AGENT"]);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($ch);
curl_close($ch);
$geo_json = json_decode($data, true);
if ($geo_json['status'] =='OK') {
// $precision = $geo_json['Placemark'][0]['AddressDetails']['Accuracy'];
$latitude = $geo_json['results'][0]['geometry']['location']['lng'];
$longitude = $geo_json['results'][0]['geometry']['location']['lat'];
$sql = "update e107_user_extended set user_lo='$longitude', user_la='$latitude' where user_extended_id=$uei";
if (!mysql_query($sql,$link)) {
die('Error: ' . mysql_error());
}
} else {
// echo "Error in geocoding! Http error ".substr($data,0,3);
}
}
Well I’m not a PHP coder like yourself so parts of this code are not really clear to me.
I was hoping this would be JS so I can understand it a bit more.
How would you implement it ? In the events ? Do you have anything working at this moment ?
Art