为什么无法根据谷歌地图地理编码geometry.bounds找到位置,但可以通过MongoDB中的geometry.vi
Why does unable to find locations based on Google Maps geocoding geometry.bounds but possible by geometry.viewport in MongoDB?
我有以下文件,地址位于新西兰惠灵顿:
{
"name": "Wellington New Zealand",
"location": [
174.77623600000004,
-41.2864603
]
}
我使用谷歌地理编码来获取字符串"新西兰"的国家边界,如下所示:
geocoder.geocode('New Zealand', function(err, res) {
console.log(res);
});
结果如下:
{
"address_components": [{
"long_name": "New Zealand",
"short_name": "NZ",
"types": ["country", "political"]
}],
"formatted_address": "New Zealand",
"geometry": {
"bounds": {
"northeast": {
"lat": -29.2313419,
"lng": -175.831536
},
"southwest": {
"lat": -52.61941849999999,
"lng": 165.8694369
}
},
"location": {
"lat": -40.900557,
"lng": 174.885971
},
"location_type": "APPROXIMATE",
"viewport": {
"northeast": {
"lat": -34.1295578,
"lng": 179.0625357
},
"southwest": {
"lat": -52.61941849999999,
"lng": 165.8700053
}
}
},
"place_id": "ChIJh5Z3Fw4gLG0RM0dqdeIY1rE",
"types": ["country", "political"]
从上面的输出中可以看到,有geometry.bounds
和geometry.viewport
对象。我正在尝试查找基于bounds
的文档,如下所示:
db.collection.find({
"location": {
"$geoWithin": {
$box: [
[bounds.southwest.lng, bounds.southwest.lat],
[bounds.northeast.lng, bounds.northeast.lat]
]
}
}
});
不幸的是,这个查询没有返回任何文档,但当我使用viewport
时,我可以很好地获得文档:
db.collection.find({
"location": {
"$geoWithin": {
$box: [
[viewport.southwest.lng, viewport.southwest.lat],
[viewport.northeast.lng, viewport.northeast.lat]
]
}
}
});
你能解释一下为什么我不能用bounds
来获取文档,而可以用viewport
来获取文档吗?我应该如何正确处理?
更新:我已经研究过geometry.bounds
是边界,geometry.viewport
是视口
可以解释一下geometry.bounds
和geometry.viewport
之间的区别是什么,我应该使用什么?
30.335098600000038,59.9342802不在您(新西兰)的范围内。它在伊朗的一个荒无人烟的地方。
相关文章:
- jquery试图按名称获取按钮位置
- 我可以获得相对于被点击元素的确切点击位置吗
- 谷歌地图固定位置覆盖
- 在单击任何位置时隐藏元素,而不检查每次DOM单击
- 循环比赛位置算法
- es6 相当于下划线查找位置
- jQuery循环在特定位置暂停
- 引导程序:在导航栏中,显示悬停在单个位置的基于Li Link的不同内容
- 自定义函数中的光标位置
- 安卓平台上的QWebView HTML5地理位置
- DIV并排,位置不正确
- 使用jQuery更改元素的顶部位置
- 在谷歌地图上绘制位置数据库
- 跟踪jqplot垂直折线图的鼠标位置
- 设置画布渲染器的x和y位置
- 固定位置菜单时滚动,直到它击中一个相对容器的底部
- 根据页面的位置突出显示文本中的字符
- 传单缩放控制位置错误
- 为什么无法根据谷歌地图地理编码geometry.bounds找到位置,但可以通过MongoDB中的geometry.vi
- Google Maps API v3 - google.maps.geometry.poly.contains位置第一次