2017-04-01 44 views
-2

我试图通过纬度和经度作为PHP变量来获取静态的谷歌地图,但是这只是拿起一个图像尽管改变共同纵线。请帮助查询谷歌地图使用PHP

*

<?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; ?>"/> 

回答

0

改变双引号括起来,以便$纬度和经度$变量被读取

单引号的字符串被读为

https://maps.googleapis.com/maps/api/staticmap?center=($纬度,$经度)&变焦= 20 &大小= 640x640 &地图类型=卫星&键=的myKey

那里为你希望它读作

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

所以你的字符串更改为

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

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

+0

但是由于某些原因,变量并没有采用浮点值,请您引用可能的原因 – Quest123

+0

我试着移动Google Map返回的图像并将其保存到mongo数据库中,再次返回 $ mapImgName = $ time。“google-map.PNG”; $ imagePath = $ destfolder。$ mapImgName; file_put_contents($ imagePath,file_get_contents($ src)); MongoCursor :: $ timeout = -1 ; $ M =新MongoClient(); $分贝= $ M-> MYDB; $网格= $ DB-> getGridFS(); $路径= “$ destfolder”; $文件名= $ mapImgName; $ storedfile = $ grid-> storeFile(“$ imagePath”,array(“met adata“=> array(”filename“=> $ filename,”date“=> new MongoDate()))); echo gettype($ imagePath); ?> “> – Quest123

0

你已经错过了13行分号因此改变$imagePath=$destfolder.$mapImgName$imagePath=$destfolder.$mapImgName;,它应该工作

+0

我做的代码进行一些改变,我试图地图推到MongoDB的。我现在无法看到地图,请帮忙。 – Quest123

+0

我试着移动从Google Map返回的图像并将其保存到mongo数据库,但图像不会再返回 $ destfolder ='C:/ xampp1/htdocs/Images /'; $ 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()))); ?>“> – Quest123