如何计算纬度和经度指定的两点之间的距离?
为了澄清,我想要以公里为单位的距离; 这些要点使用WGS84系统,我想了解可用方法的相对准确性.
请记住,我将在lat/long对上执行计算,哪种数据类型最适合与MySQL数据库一起使用?
我想制作一个应用程序来检查用户所在的最近的地方.我可以很容易地获得用户的位置,我已经有了纬度和经度的地方列表.
知道列表最近的位置与当前用户位置的最佳方法是什么.
我在谷歌API中找不到任何东西.
这里的问题并不完全是如何通过R绘制地图,因为我已经发现这里有一个非常好的例子,而是如何让它工作.实际上,我无法加载库rgdal:
library(rgdal)
Error in library(rgdal) : there is no package called ‘rgdal’
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试手动安装上面的包时,我收到以下错误:
....
configure: error: proj_api.h not found in standard or given locations.
ERROR: configuration failed for package ‘rgdal’
* removing ‘/home/eualin/R/i686-pc-linux-gnu-library/2.15/rgdal’
Warning in install.packages : installation of package ‘/home/eualin/Downloads/rgdal_0.8-5.tar.gz’ had non-zero exit status
Run Code Online (Sandbox Code Playgroud)
欢迎任何投入!
以下代码表示将map传递const给operator[]方法会丢弃限定符:
#include <iostream>
#include <map>
#include <string>
using namespace std;
class MapWrapper {
public:
const int &get_value(const int &key) const {
return _map[key];
}
private:
map<int, int> _map;
};
int main() {
MapWrapper mw;
cout << mw.get_value(42) << endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
这是因为地图访问中可能出现的分配吗?没有地图访问的函数可以声明为const吗?
MapWrapper.cpp:10: error: passing ‘const std::map<int, int, std::less<int>, std::allocator<std::pair<const int, int> > >’ as ‘this’ argument of ‘_Tp& std::map<_Key, _Tp, _Compare, _Alloc>::operator[](const _Key&) [with _Key = int, _Tp = int, _Compare = std::less<int>, _Alloc …
我正在尝试迭代打字稿地图,但我一直收到错误,我找不到任何解决方案,因为这样一个微不足道的问题.
我的代码是:
myMap : Map<string, boolean>;
for(let key of myMap.keys()) {
console.log(key);
}
Run Code Online (Sandbox Code Playgroud)
我得到错误:
类型'IterableIteratorShim <[string,boolean]>'不是数组类型或字符串类型.
完整堆栈跟踪:
错误:Typescript发现以下错误:/home/project/tmp/broccoli_type_script_compiler-input_base_path-q4GtzHgb.tmp/0/src/app/project/project-data.service.ts(21,20):输入'IterableIteratorShim <[string ,boolean]>'不是数组类型或字符串类型.在BroccoliTypeScriptCompiler._doIncrementalBuild(/home/project/node_modules/angular-cli/lib/broccoli/broccoli-typescript.js:115:19)BroccoliTypeScriptCompiler.build(/ home/project/node_modules/angular-cli/lib/broccoli/broccoli-typescript.js:43:10)在/home/project/node_modules/broccoli-caching-writer/index.js:152:21在lib $ rsvp $$ internal $$ tryCatch(/ home/project/node_modules/rsvp) /dist/rsvp.js:1036:16)lib $ rsvp $$内部$$ invokeCallback(/home/project/node_modules/rsvp/dist/rsvp.js:1048:17)在lib $ rsvp $$ internal $$发布(/home/project/node_modules/rsvp/dist/rsvp.js:1019:11)在lib $ rsvp $ asap $$ flush(/home/project/node_modules/rsvp/dist/rsvp.js:1198:9) at_combinedTickCallback(internal/process/next_tick.js:67:7)at process._tickCallback(internal/process/next_tick.js:98:9)
我正在使用angular-cli beta5和typescript 1.8.10,我的目标是es5.有没有人有这个问题?
有没有办法在页面中嵌入/混搭OpenStreetMap(就像Google Maps API的工作方式一样)?
我需要在页面内部显示带有一些标记的地图,并允许拖动/缩放,可能是路由.我怀疑会有一些Javascript API,但我似乎无法找到它.
我无法找到有关如何拦截新版Google Maps API v2上的地图触摸的示例.
我需要知道用户何时触摸地图以停止线程(地图围绕我当前位置的居中).
我有一个像这样的表驱动测试用例:
func CountWords(s string) map[string]int
func TestCountWords(t *testing.T) {
var tests = []struct {
input string
want map[string]int
}{
{"foo", map[string]int{"foo":1}},
{"foo bar foo", map[string]int{"foo":2,"bar":1}},
}
for i, c := range tests {
got := CountWords(c.input)
// TODO test whether c.want == got
}
}
Run Code Online (Sandbox Code Playgroud)
我可以检查长度是否相同,并编写一个循环来检查每个键值对是否相同.但是当我想将它用于另一种类型的地图时(例如map[string]string),我必须再次编写此检查.
我最终做的是,我将地图转换为字符串并比较字符串:
func checkAsStrings(a,b interface{}) bool {
return fmt.Sprintf("%v", a) != fmt.Sprintf("%v", b)
}
//...
if checkAsStrings(got, c.want) {
t.Errorf("Case #%v: Wanted: %v, got: %v", i, c.want, got)
}
Run Code Online (Sandbox Code Playgroud)
这假设等效映射的字符串表示是相同的,在这种情况下似乎是正确的(如果键是相同的,那么它们散列到相同的值,因此它们的顺序将是相同的).有一个更好的方法吗?在表驱动测试中比较两个映射的惯用方法是什么?
我正在尝试将纬度/长点转换为2d点,以便我可以将它显示在世界的图像上 - 这是一个墨卡托投影.
我已经看到了各种方法来做这个以及关于堆栈溢出的几个问题 - 我已经尝试了不同的代码片段,虽然我得到了像素的正确经度,但纬度总是偏离 - 似乎越来越合理了.
我需要公式来考虑图像大小,宽度等.
我试过这段代码:
double minLat = -85.05112878;
double minLong = -180;
double maxLat = 85.05112878;
double maxLong = 180;
// Map image size (in points)
double mapHeight = 768.0;
double mapWidth = 991.0;
// Determine the map scale (points per degree)
double xScale = mapWidth/ (maxLong - minLong);
double yScale = mapHeight / (maxLat - minLat);
// position of map image for point
double x = (lon - minLong) * xScale;
double y …Run Code Online (Sandbox Code Playgroud) maps ×10
android ×2
math ×2
2d ×1
algorithm ×1
api ×1
c++ ×1
const ×1
equivalence ×1
geolocation ×1
go ×1
google-maps ×1
haversine ×1
iterator ×1
java ×1
javascript ×1
mapping ×1
mercator ×1
mysql ×1
r ×1
stl ×1
table-driven ×1
testing ×1
touch ×1
typescript ×1