php - 如何获取给定城市/国家的经度/纬度?

标签 php javascript html

例如,当我在http://www.infoghidromania.com/harta_romania.html上输入地址时网站,然后按提交,它应该提取 GPS 坐标。

最佳答案

该网站使用谷歌地图 API。您可以使用相同的 API 来获取您可以在 Google map 上找到的任何位置的经度/纬度。

Javascript 代码示例:

var geocoder =  new google.maps.Geocoder();
geocoder.geocode( { 'address': '<YOUR_SEARCH_STRING_HERE>' }, function(results, status) {
    if (status == google.maps.GeocoderStatus.OK) {
        alert("Lang/Lat : " + results[0].geometry.location.lat() + " " +results[0].geometry.location.lng()); 
    } else {
        alert('Error: ' + status);
    }
});

工作示例:

关于php - 如何获取给定城市/国家的经度/纬度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16984688/

相关文章:

php - 仅来自 PHP : Unable to connect APNS gateway. push.apple.com:2195

php - 拉维尔 : How to send image or file to API

php - PDO 从选择查询中获取一列

javascript - 如何使用javascript获取updatepanel中的回发元素?

javascript - 使用 Javascript 根据总和对一组数字进行排序

jquery - 在没有列包装器的情况下并排 float 堆叠的 div

html - 填充父级的剩余宽度

javascript - 如何检索 HTML 元素的实际宽度和高度?

php - HTML5 Builder - 更改页面和组合框中的奇怪字符

JavaScript 范围