我怎样才能以编程方式获取纬度,位置的经度或使用api [英] how i can get latitude , longitude of a location programmatically or using a api
本文介绍了我怎样才能以编程方式获取纬度,位置的经度或使用api的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是获取位置经纬度的任何方法。如果是的话,那么怎么做。
是使用google map api执行此操作的任何方式。
>
// GOOGLE MAPS API v3
// API:https://developers.google.com/maps/documentation/geocoding/#GeocodingRequests
//示例JSON请求:http ://maps.googleapis.com/maps/api/geocode/json?address = 1111%20W。%2035rd%20street,%20Chicago,%20IL& sensor = true
function GoogleURI(address,type){
var uri =http://maps.googleapis.com/maps/api/geocode/;
// address = FormatAddress(address);
if(type ==xml){
uri = uri + type +? +address =+ address +%26sensor = false;
} else {//默认为json
uri = uri +json+? +address =+ address +%26sensor = false;
}
return uri;
}
//开放街道地图API 0.6
// API:http://wiki.openstreetmap.org/wiki/Nominatim#Example
//示例XML请求:http://nominatim.openstreetmap.org/search?q=%201111%20W.%2035th%20Street%2C%20Chicago%2C%20IL%2060609&format=xml&addressdetails=1
// NOTE&'s和空格不会轻易地传递给php,然后传递给nominatim.openstreetmap.org
//警告:开放式街道地图有时候不需要州和邮政编码,事实上会误报......;)
函数OpenURI(地址,类型){
var uri =http://nominatim.openstreetmap.org/search?q=;
var format =%26format =+ type;
var details =%26addressdetails = 1;
// address = FormatAddress(address);
//注意:&'s不会传递给php file_get_contents($ uri)不要使用& polygon = 1& addressdetails = 1;
if(type ==xml){
uri = uri + address +%26format =+ type +%26addressdetails = 1;
} else {//默认为json
uri = uri + address +%26format =+json+%26addressdetails = 1;
}
return uri;
$ / code> 然后,您可以从上述方法发送返回的uri并执行GET请求在PHP中。
are any way to get the latitude or longitude of a location. if yes then how.
are any way to do this using google map api.
解决方案 Here is an example of how to do a request using JavaScript for Open Street Maps or Google Maps.
// GOOGLE MAPS API v3
// API: https://developers.google.com/maps/documentation/geocoding/#GeocodingRequests
// Example JSON request: http://maps.googleapis.com/maps/api/geocode/json?address=1111%20W.%2035rd%20street,%20Chicago,%20IL&sensor=true
function GoogleURI(address, type){
var uri = "http://maps.googleapis.com/maps/api/geocode/";
//address = FormatAddress(address);
if(type == "xml"){
uri = uri + type + "?" + "address=" + address + "%26sensor=false";
} else { // default to json
uri = uri + "json" + "?" + "address=" + address + "%26sensor=false";
}
return uri;
}
// OPEN STREET MAP API 0.6
// API: http://wiki.openstreetmap.org/wiki/Nominatim#Example
// Example XML Request: http://nominatim.openstreetmap.org/search?q=%201111%20W.%2035th%20Street%2C%20Chicago%2C%20IL%2060609&format=xml&addressdetails=1
// NOTE &'s and spaces dont pass easily to php and then to nominatim.openstreetmap.org
// WARNING: OPEN STREET MAPS SOMETIMES DOESNT NEED THE STATE AND ZIP CODE and in fact will error out... ;)
function OpenURI(address, type){
var uri = "http://nominatim.openstreetmap.org/search?q=";
var format = "%26format=" + type;
var details = "%26addressdetails=1";
//address = FormatAddress(address);
// NOTE: &'s dont pass good to php file_get_contents($uri) dont use "&polygon=1&addressdetails=1";
if(type == "xml"){
uri = uri + address + "%26format=" + type + "%26addressdetails=1";
} else { // default to json
uri = uri + address + "%26format=" + "json" + "%26addressdetails=1";
}
return uri;
}
You can then send the return uri from the above methods and do a GET request in PHP.
这篇关于我怎样才能以编程方式获取纬度,位置的经度或使用api的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文