简体   繁体   English

生成带有地址字符串的Googlemaps

[英]Generate Googlemaps with address string

I am pretty new to the Google API. 我是Google API的新手。 I have in my database some addresses information stored and I am calling it to my page with a PHP while loop. 我的数据库中存储了一些地址信息,并使用PHP while循环将其调用到页面中。 What I would like is that it shows the location of the address in Googlemaps based on street name and city stored in database. 我想要的是它根据存储在数据库中的街道名称和城市显示Googlemaps中地址的位置。

The only way I see how to use Google maps is with latitude and longitude. 我看到如何使用Google地图的唯一方法是经度和纬度。 Is there a way to convert the street name and city into these coordinates so it generate correct maps location on my website? 有没有一种方法可以将街道名称和城市转换为这些坐标,从而在我的网站上生成正确的地图位置?

I hope someone can provide me with an answer. 我希望有人能给我答案。 Thank you in advance. 先感谢您。

I found a PHP solution that generates the lat and lng that works for me. 我找到了一个PHP解决方案,该解决方案可以生成对我有用的经纬度。 Hopefully also for you. 希望也能为您服务。

// Get the JSON 
$url='http://maps.googleapis.com/maps/api/geocode/json?address=2+bis+avenue+Foch75116+Paris+FR&sensor=false';
$source = file_get_contents($url);
$obj = json_decode($source);
$lat = $obj->results[0]->geometry->location->lat;
$lng = $obj->results[0]->geometry->location->lng;
echo $lat;

It generates a JSON with the address and with PHP you can get the lat and lng. 它使用地址生成一个JSON,使用PHP可以获取lat和lng。 Just add your address in the $url string after "address=" 只需在“地址=”后面的$ url字符串中添加您的地址

Use http://maps.google.com/maps?q= and add the adress string at the end of the url. 使用http://maps.google.com/maps?q=并在网址末尾添加地址字符串。

If you want to use it for mobile look at the question. 如果您想将其用于移动设备,请查看问题。 Suppress chooser dialog when calling Google map using intent 使用Intent调用Google地图时禁止选择器对话框

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM