Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google maps 根据地图的三角度,如何知道当前是否查看了地图中的某个点?_Google Maps_React Native_Google Maps Api 3 - Fatal编程技术网

Google maps 根据地图的三角度,如何知道当前是否查看了地图中的某个点?

Google maps 根据地图的三角度,如何知道当前是否查看了地图中的某个点?,google-maps,react-native,google-maps-api-3,Google Maps,React Native,Google Maps Api 3,我需要知道用户当前是否查看了地图上的某个位置, 例如,我有一个观点 {latitude:40,longtude:32} 地图的视图是由 {纬度:32,纬度:44,纬度德尔塔:0.003,纬度德尔塔:0.005} 当地图放大和缩小时,数据中唯一的差异就是纬度delta和经度delta 最终,当我越来越缩放时,地图上的点将不再可见 有人能帮我建立这个计算吗?这将非常有用我不能给你一个编码的解决方案,但你可以: 从三角形中获取直径(从地图的两个角度): 然后计算两个位置之间的距离: function

我需要知道用户当前是否查看了地图上的某个位置, 例如,我有一个观点

{latitude:40,longtude:32}

地图的视图是由

{纬度:32,纬度:44,纬度德尔塔:0.003,纬度德尔塔:0.005}

当地图放大和缩小时,数据中唯一的差异就是纬度delta和经度delta

最终,当我越来越缩放时,地图上的点将不再可见


有人能帮我建立这个计算吗?这将非常有用

我不能给你一个编码的解决方案,但你可以:

从三角形中获取直径(从地图的两个角度):

然后计算两个位置之间的距离:

function distance(lon1, lat1, lon2, lat2) {
  const R = 6371 // Radius of the earth in km
  const dLat = (lat2 - lat1).toRad() // Javascript functions in radians
  const dLon = (lon2 - lon1).toRad()
  const a = Math.sin(dLat / 2) * Math.sin(dLat / 2) +
          Math.cos(lat1.toRad()) * Math.cos(lat2.toRad()) *
          Math.sin(dLon / 2) * Math.sin(dLon / 2)
  const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a))
  const d = R * c // Distance in km
  return d
}
// add this if toRad is undefined
if (typeof (Number.prototype.toRad) === 'undefined') {
  Number.prototype.toRad = function() {
    return this * Math.PI / 180
  }
}
然后使用直径和距离:

if ((diameter / 2) > distance) {
  console.log('The location in in the map')
}

非常感谢你。我相信这会很有帮助
if ((diameter / 2) > distance) {
  console.log('The location in in the map')
}