【问题标题】:Finding intermediate latitude and longitude in javascript在javascript中查找中间纬度和经度
【发布时间】:2015-02-15 08:10:20
【问题描述】:

我有以下数据。 1.来源​​名称。 2.目的地名称。 我需要在从源到目的地的路径上找到经纬度对。是否有任何 google Api 可用?我提到了这个问题Finding intermediate Lattitude Longitude between two given points,但无法理解整个事情。任何人都可以有更简单的答案吗?

编辑 这是我尝试过的

 //store lat and long
    var sd_array=[];
        $('#processbtn').click(function(e){
    //get source and destination name       
                var source=$('#source').val();
                var destination=$('#destination').val();
                if(source==''||destination==''){
                    alert("all fields required");
                }else{
                   //decode lat-long from address
                    getLatitudeAndLongitude(source);
                    getLatitudeAndLongitude(destination);
                }
            });
        function getLatitudeAndLongitude(address){
            var geocoder = new google.maps.Geocoder();
            geocoder.geocode( { 'address': address}, function(results, status) {
              if (status == google.maps.GeocoderStatus.OK) {
                var latitude = results[0].geometry.location.lat();
                var longitude = results[0].geometry.location.lng();
               //store to array
                sd_array.push(latitude);
                sd_array.push(longitude);
              }
            }); 
        }
    function getInterMediateLatLong(sd_array){
      //get intermediate locations 
      /*sd_array[0] source lat
      sd_array[1] source long
      sd_array[2] destination lat
      sd_array[3] destination long*/
    }

我需要帮助来获得中间位置。

【问题讨论】:

  • 你需要多少个“中间点”,只有一个? the Guide有什么不明白的地方?这是一个典型的XY plane 问题,您有 A、B 点,需要它们之间的一组点。
  • 需要 3 到 5 对我也是谷歌地图 API 的新手

标签: javascript google-maps cordova


【解决方案1】:

你必须首先明白它是一个Mathematical problem,但是很简单。谷歌将返回一组 o XY 点...过程是:

  1. 正确表达“参考点”SDS来源和D目的地。所以 Sx,Sy,Dx,Dy。它们不是“名称”,是 XY coodenates (!)。

  2. 查看如何告诉 Google-API 你需要多少积分

  3. 将您的查询提交给 Google-API:编辑您的问题以向我们展示您的查询(Javascript 代码)!我们可以在这里讨论。


你需要表达

{path[]: LatLngPathes, samples: 4}

获取LatLngPathes的Javascript片段示例:

 var source = new google.maps.LatLng(36.578581, -118.291994);
 var destination = new google.maps.LatLng(36.606111, -118.062778);

【讨论】:

  • 感谢详细解答。让我试试
  • 先生,我已经编辑了我的问题,请看看这个
【解决方案2】:

由于每个 lat 和 lon 的基础类型都是实数(AKA double 或 float),只需添加源变量和端点变量并将每个结果除以 2.0。

var mid_lat = (lat_source + lat_dest ) / 2.0 ;
var mid_lon = (lon_source + lon_dest ) / 2.0 ;

那么中点的坐标就是 mid_lat, mid_lon 。

【讨论】:

  • 我不明白你的意思
猜你喜欢
  • 1970-01-01
  • 2023-03-13
  • 1970-01-01
  • 1970-01-01
  • 2012-09-07
  • 1970-01-01
  • 2018-09-09
  • 2016-05-08
  • 2017-11-10
相关资源
最近更新 更多