I made a short code to calculate distance using Google Maps API. My problem is that the code works fine on one server, but not on another. It is the axact same code copied from one place to antother. I can't figure out whats wrong. Can anyone help me?
$server="https://maps.googleapis.com/maps/api/directions/json?origin=".$from.",Sweden&destination=".$to.",Sweden";
if($stream = fopen( $server,r)){
$klart=json_decode(stream_get_contents($stream),true);
fclose($stream);
$distans = $klart['routes'][0]['legs'][0]['distance'][text];
$kilometer=split(" ",$distans);
$km = $kilometer[0];
$kostnad = $km * ((2.1*1.15)*1.25)/5;
}
Thank you! Anders
Edit 1: Thank you all for your comments. It seems that it was a javascript that interfered with the html-form. I've added a script to autocomplete the cities (variables $to and $from). When I comment out the javascript, the php code works fine.