问题描述
我的大型数据库中有邮政编码,其中包含 SL5 9JH、LU1 3TQ 等值.
I have Postcode in my large database, which contains values like SL5 9JH, LU1 3TQ etc.
现在,当我将上面的邮政编码粘贴到 maps.google.com 时,它指向一个完美的位置..
Now when I am pasting above postcode to maps.google.com it's pointing to a perfect location..
我的要求是我想将邮政编码传递给 maps.google.com,它应该返回我想存储在我的数据库中的那个指向位置的相关纬度和经度.
My requirement is like I want to pass post codes to maps.google.com and it should return a related latitude and longitude of that pointed location, that I want to store in my database.
所以,很可能应该有一些 javascript... 如果有人对此有其他想法,请提供它..
So, most probably there should be some javascript for that... If anybody have another idea regarding that please provide it..
提前谢谢...
推荐答案
您描述的过程的技术术语称为 反向地理编码.Google 提供 Google 地理编码网络服务 新的 Google 地理编码链接,您可以在其中进行反向操作在服务器端进行地理编码,而不是在客户端使用 JavaScript.
The technical term for the process you describe is called reverse geocoding. Google offers the The Google Geocoding Web Service New working Google Geocoding Link, where you can do reverse geocoding on the server side, instead of in JavaScript on the client-side.
例如,如果您在浏览器中尝试以下 URL,您将返回 q
参数中传递的邮政编码的纬度和经度,格式为 CSV:
For example, if you try the following URLs in your browser, you would get back the latitude and longitude of the postcode passed in the q
parameter, in CSV format:
http://maps.google.com/maps/geo?q=SL59JH,+UK&output=csv&sensor=false
http://maps.google.com/maps/geo?q=LU13TQ,+UK&output=csv&sensor=false
这是您可以在 php 中对邮政编码进行反向地理编码的方式,例如:
This is how you would be able to reverse geocode your postcodes in php, for example:
$url = 'http://maps.google.com/maps/geo?q=SL59JH,+UK&output=csv&sensor=false';
$data = @file_get_contents($url);
$result = explode(",", $data);
echo $result[0]; // status code
echo $result[1]; // accuracy
echo $result[2]; // latitude
echo $result[3]; // longitude
请注意,作为 Pekka 在另一个答案中建议,Google Maps API 使用条款 似乎禁止存储结果,除非store 充当将在 Google 地图中使用的数据的缓存.您可能想与 Google 取得联系并查询 Google Maps API Premier 为您的地理编码要求提供更灵活的使用条款.
Note that as Pekka suggested in another answer, the Google Maps API Terms of Use seem to prohibit the storage of the results, unless the store acts as a cache for data that will used in Google Maps. You may want to get in touch with Google and enquire on the Google Maps API Premier to have more flexible terms of use for your geocoding requirements.
这篇关于通过使用 Javascript 将邮政编码传递给 maps.google.com 来获取纬度经度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!