Reputation: 579
I have a javascript to take my current position and draw it in Google Maps, but I would like to have,also, the coordinates in variable usable in PHP . I have :
<script src="http://maps.google.com/maps/api/js?sensor=true"></script>
<script type="text/javascript">
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(mostra_mappa);
}else{
alert('La geo-localizzazione NON è possibile');
}
function mostra_mappa(position) {
var punto = new google.maps.LatLng(position.coords.lat, position.coords.long),
opzioni = {
zoom: 15,
center: punto,
mapTypeId: google.maps.MapTypeId.ROADMAP
},
contenitore = document.getElementById("mia_mappa"),
mappa = new google.maps.Map(contenitore, opzioni),
marker = new google.maps.Marker({
position: punto,
map: mappa,
title: "Tu sei qui!"
});
}
</script>
Now, I would like to take the coordinates x and y (previous computed) of my position and put its into the request(as follow) :
$x =?????;
$y=??????;
$String = file_get_contents('http://api.yelp.com/business_review_searchterm=restaurant&lat=' . $x.'&long='. $y . '&radius=20&limit=500&ywsid=uHhsYI82_aEk8Q9NjSsIzg');
Could you help me?
Upvotes: 0
Views: 2376
Reputation: 1567
Just send your coordinates to the PHP file. Javascript...
var data = {
'x': position.coords.lat,
'y': position.coords.lon
};
$.post('script.php', { coordinates: JSON.stringify(data) }, function () {
// deal with your returned Yelp review...
});
PHP...
if (isset($_POST['coordinates'])) {
$geo = json_decode($_POST['coordinates']);
$x = $geo.x;
$y= $geo.y;
// get Yelp review here
}
Upvotes: 1