Separate function for longitude and latitude
Hey,
I got this function of the internet to convert an address from a database into coordinates, but i need them separately. Can anyone help to separate the code into two, so i can have one variable for the longitude and one for the latitude.
<!doctype html>
<html>
<head>
<link href="style.css" rel="stylesheet" type="text/css">
<meta charset="utf-8">
<title>Untitled Document</title>
</head>
<body>
<?php
include('db.php');
$bestel_id = $_COOKIE['bestelnum'];
$query = "select Adres, Postcode, Stad from Bestelling where Bestel_id = '$bestel_id'";
$result = mysql_query($query) or die (mysql_error());
while ($row = mysql_fetch_array($result)) {
$plaats = "$row[Adres] $row[Postcode] $row[Stad]";
}
function getCoordinates($address){
$address = str_replace(" ", "+", $address); // replace all the white space with "+" sign to match with google search pattern
$url = "http://maps.google.com/maps/api/geocode/json?sensor=false&address=$address";
$response = file_get_contents($url);
$json = json_decode($response,TRUE); //generate array object from the response from the web
return ($json['results'][0]['geometry']['location']['lat'].",".$json['results'][0]['geometry']['location']['lng']);
}
echo getCoordinates($plaats);
?>
</body>
</html>
Thanks!!
