我正在尝试使用 R 查找两点之间的距离。虽然我已经看到了其他答案(从数据框到特定位置查找最近的城市),但我想使用特定的公式来计算以英里为单位的距离。在另一个网站(https://andrew.hedges.name/experiments/haversine/)上,我发现 Java 中的这段代码在 GUI 中给出了正确的距离:
dlon = lon2 - lon1
dlat = lat2 - lat1
a = (sin(dlat/2))^2 + cos(lat1) * cos(lat2) * (sin(dlon/2))^2
c = 2 * atan2( sqrt(a), sqrt(1-a) )
d = 3961 * c
Run Code Online (Sandbox Code Playgroud)
然后我将其转换为 R 中的函数:
geo_distance <- function(lon2, lon1, lat2, lat1){
dlon <- lon2 - lon1
dlat <- lat2 - lat1
a <- (sin(dlat/2))^2 + cos(lat1) * cos(lat2) * (sin(dlon/2))^2
c <- 2 * atan2(sqrt(a), sqrt(1-a))
d <- 3961 …Run Code Online (Sandbox Code Playgroud) 我正在尝试访问地理编码服务器的 REST API:
[ https://locator.stanford.edu/arcgis/rest/services/geocode/USA_StreetAddress/GeocodeServer] (ArcGIS Server 10.6.1)
...使用 POST 方法(顺便说一句,可以使用一两个示例,似乎只有关于何时使用 POST 的非常简短的“注释”,而不是如何使用:https: //developers.arcgis.com/rest /geocode/api-reference/geocoding-geocode-addresses.htm#ESRI_SECTION1_351DE4FD98FE44958C8194EC5A7BEF7D)。
我正在尝试使用 requests.post(),并且我认为我已经成功地接受了令牌等...,但我不断收到 400 错误。
根据以前的经验,这意味着数据格式有些问题,但我直接从 Esri 支持网站剪切并粘贴了这个测试对。
# import the requests library
import requests
# Multiple address records
addresses={
"records": [
{
"attributes": {
"OBJECTID": 1,
"Street": "380 New York St.",
"City": "Redlands",
"Region": "CA",
"ZIP": "92373"
}
},
{
"attributes": {
"OBJECTID": 2,
"Street": "1 World Way",
"City": "Los Angeles",
"Region": "CA",
"ZIP": "90045"
}
}
]
}
# Parameters
# Geocoder endpoint …Run Code Online (Sandbox Code Playgroud) 点击跟随脚本的页面显示:
为什么当lat未定义时,lon不是?可以在这里找到一个工作示例.
拉起你的网络控制台,亲眼看看吧!
$(document).ready(function(){
var geocoder;
function codeAddress()
{
geocoder = new google.maps.Geocoder();
var address = 'London, England';
geocoder.geocode({'address': address}, function(results, status)
{
if (status == google.maps.GeocoderStatus.OK)
{
lat = results[0].geometry.location.Ia;
lon = results[0].geometry.location.Ja;
console.log("lat: " + lat);
console.log("lon: " + lon);
}
});
}
codeAddress();
});
</script>
</head>
<body>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
我们在这里 - Ia和Ja的历史意义是什么?我认为它涉及笛卡尔单位向量i和j(主要用于工程),虽然我不确定.
我在网上找到了其他使用.latfor .Ia和.lngfor的例子.Ja
但是,这些会在控制台中返回:
function () {
return this[a];
}
Run Code Online (Sandbox Code Playgroud)
只需要朝正确的方向发起冲击.谢谢.
是否有通用的JavaScript或可能的Python/Django或其他开源Web服务或API来查找给定街道地址的地理位置?http://www.braincastexception.com/wp7-web-services-first-part-geocodeservice/做了我想要的,显然是在C#中.是否可以从JavaScript或可查询的开源项目中获得?
ATdhvaanckse,
我正在尝试累积地址,以便将它们绘制在R中的地图上.我手动获取地址并将它们输入到.csv中以导入到R.中.csv的格式如下:
streetnumber | 街道| 城市| 州
1150 | FM 1960 West Road | 休斯顿| TX
701 | 凯勒百汇| 凯勒| TX
每个标题(街道号,街道,城市和州)用于唯一列,下面的数据分为各自的列.
我让R读取.csv中的信息并将其转换为适合Google Maps API使用的格式.我有API生成一个.xml文件,其中包含与输入的地址相对应的信息.最小的工作示例如下:
streetnumber1<-paste(data$streetnumber,sep="")
street1<-gsub(" ","+",data$street)
street2<-paste(street1,sep="")
city1<-paste(data$city,sep="")
state1<-paste(data$state,sep="")
url<-paste("http://maps.googleapis.com/maps/api/geocode/xml?address="
,streetnumber1,"+",street2,",+",city1,",+",state1,"&sensor=false",sep="")
Run Code Online (Sandbox Code Playgroud)
通过调用url生成两个可以输入Web浏览器的Web地址,以导航到Google Maps API提供的.xml数据.
我想为.csv文件中的所有地址发生这种情况,而不是我声明应该生成url的次数.我觉得这是一个apply功能的工作,但我不确定如何去做.一旦我自动化R和API之间的交互,我想解析获得的.xml,以便我可以提取我正在寻找的信息.
我想自动将标记移动到x公里.
这是我的代码:
geocoder.geocode({'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var myMap = new google.maps.LatLng(-34.397, 150.644);
var myOptions = {
zoom: 11,
center: myMap,
scrollwheel: false,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
var map = new google.maps.Map(document.getElementById("show_map"), myOptions);
map.setCenter(results[0].geometry.location);
var marker = new google.maps.Marker({
position: results[0].geometry.location,
flat: false,
map: map
});
}
}
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?
谢谢.
我目前正试图通过在PHP页面中使用Google Geocode API来获取地址的lat和lng参数.
我目前有以下代码,但不知何故,它不能通过PHP工作,而将生成的地址复制到谷歌浏览器似乎确实有效.
任何人都可以在下面的代码中看到错误吗?
提前致谢!
汤姆
================================================== ==
返回的错误是:
( [error_message] => The 'sensor' parameter specified in the request must be set to either 'true' or 'false'. [results] => Array ( ) [status] => REQUEST_DENIED ) An error has occured: 1
Run Code Online (Sandbox Code Playgroud)
旧代码与过时的部分:
$googleQuery = $_POST['txtAdres'] . ',+' . $_POST['txtPostcode'] . '+' . $_POST['txtStad'] . ',+' . $_POST['txtLand'];
$googleQuery = str_replace(' ', '+', $googleQuery);
// retrieve the latitude & longitude from the address
$url = 'http://maps.googleapis.com/maps/api/geocode/json?address=' . urlencode($googleQuery) . '&sensor=false'; …Run Code Online (Sandbox Code Playgroud) 在Google表格中,我有一列包含经纬度坐标。列表来自A2:A1000。我还分别在B1,C1和D1中有城市,州和国家/地区的列。我可以运行一个公式或脚本来读取坐标并在其各自的列中提供城市,州和国家/地区吗?我不知道如何使用JavaScript,XML,JSON,序列化PHP等,因此,如果您的建议包括其中之一,请提供一些说明。提前致谢。
geocoding latitude-longitude google-sheets reverse-geocoding
I try to do geocoding of French addresses. I'd like to use the following website : http://adresse.data.gouv.fr/
There is an example on this website on how is working the API but I think it's some Linux code and I'd like to translate in R code. The aim is to give a csv file with addresses and the result should be geo coordinates.
Linux code (example give on the website)
http --timeout 600 -f POST http://api-adresse.data.gouv.fr/search/csv/ data@path/to/file.csv
Run Code Online (Sandbox Code Playgroud)
I tried to "translate" …
我正在搜索我的数据库检查地址并使用Geocode找到lat/lng.一旦我点击一个空值的记录,它就会移动到catch.知道如何让它移动到下一个记录吗?
static void Main(string[] args)
{
using (SqlConnection con = new SqlConnection())
{
con.ConnectionString = "Data Source Here";
con.Open();
SqlDataReader reader;
try
{
reader = new SqlCommand("select PHAddress4, PHAddress5 from FLC_ProspectHeaderTable", con).ExecuteReader();
if (reader.HasRows)
{
while (reader.Read())
{
Console.WriteLine(reader["PHAddress4"].ToString());
Console.WriteLine(reader["PHAddress5"].ToString());
var address = (reader["PHAddress5"].ToString());
var requestUri = string.Format("http://maps.googleapis.com/maps/api/geocode/xml?address={0}&sensor=false", Uri.EscapeDataString(address));
var request = WebRequest.Create(requestUri);
var response = request.GetResponse();
var xdoc = XDocument.Load(response.GetResponseStream());
var result = xdoc.Element("GeocodeResponse").Element("result");
var locationElement = result.Element("geometry").Element("location");
var lat = locationElement.Element("lat");
var lng = locationElement.Element("lng");
Console.WriteLine(lat);
Console.WriteLine(lng);
} …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 GeoPy 从纬度/经度对中打印特定的国家/地区代码。它可以将地址、纬度、经度或整个 JSON 作为 dict 返回,但不能返回单个组件。
有没有办法我只能访问国家部分并返回它?这是我正在使用的代码,用于输出来自地理定位器的原始响应:
from geopy.geocoders import Nominatim
geolocator = Nominatim()
Lat = input('Lat: ')
Long = input('Long: ')
location = geolocator.reverse([Lat, Long])
print(location.raw)
Run Code Online (Sandbox Code Playgroud)
这是我收到的输出:
{'许可':'数据 © OpenStreetMap 贡献者,ODbL 1.0。http://www.openstreetmap.org/copyright ', 'address': {'house_number': '1600', 'city': 'Washington', 'country_code': 'us', 'postcode': '20500', '吸引力':'白宫','街区':'纪念碑核心','国家':'美利坚合众国','州':'哥伦比亚特区','行人':'宾夕法尼亚大道西北'}, 'display_name': 'White House, 1600, 宾夕法尼亚大道西北, Monumental Core, Washington, 哥伦比亚特区, 20500, 美国', 'lat': '38.8976989', 'boundingbox': ['38.8974898', '31.89799 ', '
我在地图上绘制房地产位置。下面列出的地址映射不正确,因为它是一个新建筑物,并且我认为这条街和所有事物都是新建筑物,这就是Google在其数据库中找不到它的原因。
我想发生的是Google返回“ GeocoderStatus.ZERO_RESULTS”,而不仅仅是选择一个具有相关名称的位置并给我这些坐标。
我要绘制的地址是:
14018 Lonecreek Ave奥兰多,佛罗里达州32828
如果您通过http提交请求,则可以通过API获得与我相同的结果,请参见以下链接:http : //maps.googleapis.com/maps/api/geocode/json?address=140
您会看到它以错误的位置返回“ Lone Hill Drive”。我如何在这种情况下告诉Google返回ZERO_RESULTS状态?
我尝试使用reverseGeocoordinate显示locationEnd我的地址,DestinationSearchBar但我不知道该怎么做。
func viewController(_ viewController: GMSAutocompleteViewController, didAutocompleteWith place: GMSPlace) {
let camera = GMSCameraPosition.camera(withLatitude: place.coordinate.latitude, longitude: place.coordinate.longitude, zoom: 15.0)
if locationSelected == .startLocation {
addressSearchBar.text = "\(place.coordinate.latitude), \(place.coordinate.longitude)"
locationStart = CLLocation(latitude: place.coordinate.latitude, longitude: place.coordinate.longitude)
createMarker(titleMarker: "Punto de recojo", iconMarker: #imageLiteral(resourceName: "marker"), latitude: place.coordinate.latitude, longitude: place.coordinate.longitude)
} else {
DestinationSearchBar.text = "\(place.coordinate.latitude), \(place.coordinate.longitude)"
locationEnd = CLLocation(latitude: place.coordinate.latitude, longitude: place.coordinate.longitude)
createMarker(titleMarker: "Punto de destino", iconMarker: #imageLiteral(resourceName: "marker"), latitude: place.coordinate.latitude, longitude: place.coordinate.longitude)
self.mapView.camera = camera
self.dismiss(animated: true, completion: …Run Code Online (Sandbox Code Playgroud) geocoding ×13
google-maps ×4
python ×3
r ×3
api ×2
javascript ×2
c# ×1
curl ×1
dictionary ×1
distance ×1
function ×1
geolocation ×1
geopy ×1
google-api ×1
haversine ×1
ios ×1
php ×1
post ×1
python-2.7 ×1
rest ×1
sql-server ×1
swift ×1
xcode10 ×1
xml ×1