在Google Maps JS API上获取两点之间的点(经百分比)的纬度和经度? [英] Getting the latitude and longitude of the point in between (by percentage) two points on Google Maps JS API?

查看:91
本文介绍了在Google Maps JS API上获取两点之间的点(经百分比)的纬度和经度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 函数初始化(){
var mapOptions = {
center:{lat:21.9072222,lng:-47.715},
zoom:3
};
var map = new google.maps.Map(document.getElementById('derby-to-lima'),
mapOptions);

var line = new google.maps.Polyline({
path:[new google.maps.LatLng(53.9834124,-1.5863153),new google.maps.LatLng(-12.0553442, -
strokeColor:#008CBA,
geodesic:true,
strokeOpacity:0.5,
strokeWeight:5,
map:map
});
}
google.maps.event.addDomListener(window,'load',initialize);

我想在现有的一条线上画另一条线,分数,可以按百分比改变。这很难解释,但想象出第一点是开始,最后是结束。你可以得到目前跑步者的多少比例。现在显示它们有多远(假设它们是直线运行的)。



谢谢,我一直坚持这一点。

解决方案

正如@ Dr.Molle建议加载几何体库并使用方法 interpolate

  var startPoint = new google.maps.LatLng(53.9834124,-1.5863153 ); 
var endPoint = new google.maps.LatLng(-12.0553442,-77.0451853);
var percentage = 0.5;
var middlePoint = new google.maps.geometry.spherical.interpolate(startPoint,endPoint,percentage);



FIDDLE


Here is the code I have so far:

function initialize() {
  var mapOptions = {
    center: { lat: 21.9072222, lng: -47.715},
    zoom: 3
  };
  var map = new google.maps.Map(document.getElementById('derby-to-lima'),
      mapOptions);

  var line = new google.maps.Polyline({
    path: [new google.maps.LatLng(53.9834124, -1.5863153), new google.maps.LatLng(-12.0553442, -77.0451853)],
    strokeColor: "#008CBA",
    geodesic: true,
    strokeOpacity: 0.5,
    strokeWeight: 5,
    map: map
  });
}
google.maps.event.addDomListener(window, 'load', initialize);

I want to draw another line on top of the existing one that stops at the point in between the two points, which can be changed by percentage. It's kind of hard to explain, but imagine the first point is the start, and the last is the end. You are given how far a runner currently is by the percentage of the way through they are. Now show how far they are (assuming they ran in a straight line).

Thanks, I've been stuck on this for a while.

解决方案

As suggested by @Dr.Molle load the geometry library and use the method interpolate.

var startPoint =  new google.maps.LatLng(53.9834124, -1.5863153); 
var endPoint = new google.maps.LatLng(-12.0553442, -77.0451853);
var percentage = 0.5; 
var middlePoint = new google.maps.geometry.spherical.interpolate(startPoint, endPoint, percentage); 

FIDDLE

这篇关于在Google Maps JS API上获取两点之间的点(经百分比)的纬度和经度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆