-2

I am trying to pass the Latitude and Longitude as a variable in PHP to fetch static Google Maps , But this just picks up one Image despite of changing the co ordinates .Please help

*

<?php 
session_start();
$latitude=doubleval($_POST['latitude']);
$longitude=doubleval($_POST['longitude']);
$cordinate=$latitude.",".$longitude;
$cordinate1=doubleval($cordinate);
echo $latitude;
echo $longitude;
$src='https://maps.googleapis.com/maps/api/staticmap?center=($latitude,$longitude)&zoom=20&size=640x640&maptype=satellite&key=MyKey';
$time=strval(mktime());
$destfolder='images/';
$mapImgName=$time."google-map.PNG";
$imagePath=$destfolder.$mapImgName
file_put_contents($imagePath,file_get_contents($src));
?>
<img src="<?php echo $imagePath; ?>"/>
Quest123
  • 1
  • 1

1 Answers1

0

change it double quotes so that the $latitude and $longitude variables are read

with single quotes your string is reading as

https://maps.googleapis.com/maps/api/staticmap?center=($latitude,$longitude)&zoom=20&size=640x640&maptype=satellite&key=MyKey

where as you want it to read as

https://maps.googleapis.com/maps/api/staticmap?center=(5,10)&zoom=20&size=640x640&maptype=satellite&key=MyKey

so change your string to

"https://maps.googleapis.com/maps/api/staticmap?center=($latitude,$longitude)&zoom=20&size=640x640&maptype=satellite&key=MyKey";

source What is the difference between single-quoted and double-quoted strings in PHP?

Community
  • 1
  • 1
Luke143
  • 16
  • 2
  • The variables however are not taking float values due to some reason can you please cite what the possible cause could be – Quest123 Apr 01 '17 at 18:30
  • I tried moving the images returned from Google Map and save it to mongo DB but the image won't return again $mapImgName=$time."google-map.PNG"; $imagePath=$destfolder.$mapImgName; file_put_contents($imagePath,file_get_contents($src)); MongoCursor::$timeout = -1; $m = new MongoClient(); $db = $m->mydb; $grid = $db->getGridFS(); $path = "$destfolder"; $filename=$mapImgName; $storedfile = $grid->storeFile("$imagePath", array("metadata" => array("filename" => $filename,"date"=>new MongoDate()))); echo gettype($imagePath); ?> "> – Quest123 Apr 04 '17 at 14:53