在距离启动LAT/长坐标和完成LAT/LONG坐标的给定距离处的点的坐标坐标。

问题描述 投票:0回答:1
目前,我使用jquery&ajax

使用Google Map&Fusion表在地图上绘制了行

我需要的是沿线绘制一个点。 我拥有的是

a。启动坐标样本39.793147,-86.238922

B。完成坐标样本39.799276,-86.238922

C。从开始到情节点样品500米

(计算的坐标)39.797797,-86.238922

我的问题是,我必须能够计算出最佳选择或什么选择。

样本替代方案 例如开始39.793147,-86.238922 END 39.801703,-86.237062或该线可能具有多个点

EG

<LineString><coordinates>-86.238922,39.793147 -86.238922,39.797797 -86.238829,39.800122 -86.237062,39.801703</coordinates></LineString>

我希望我已经解释了我要实现的目标。这可能有要点并具有在这两个点之间绘制所需的距离吗?
向前介绍任何想法或样本。
非常感谢
    

一种选项是使用

MikeWilliams的Epoly Library

jquery ajax google-maps google-maps-api-3 google-fusion-tables
1个回答
1
投票

代码片段:


.GetPointAtDistance

var map; function initialize() { map = new google.maps.Map( document.getElementById("map_canvas"), { center: new google.maps.LatLng(37.4419, -122.1419), zoom: 13, mapTypeId: google.maps.MapTypeId.ROADMAP }); var lineString = [ [-86.238922, 39.793147], [-86.238922, 39.797797], [-86.238829, 39.800122], [-86.237062, 39.801703] ]; var path = []; var bounds = new google.maps.LatLngBounds(); for (var i = 0; i < lineString.length; i++) { var pt = new google.maps.LatLng(lineString[i][1], lineString[i][0]); bounds.extend(pt); path.push(pt); } var polyline = new google.maps.Polyline({ map: map, path: path }); map.fitBounds(bounds); var sMark = new google.maps.Marker({ position: { lat: lineString[0][1], lng: lineString[0][0] }, map: map, title: "Start", icon: "http://www.google.com/mapfiles/markerS.png" }); var mark = new google.maps.Marker({ position: polyline.GetPointAtDistance(500), map: map, title: "500m" }); } google.maps.event.addDomListener(window, "load", initialize); /*********************************************************************\ * * * epolys.js by Mike Williams * * updated to API v3 by Larry Ross * * * * A Google Maps API Extension * * * * Adds various Methods to google.maps.Polygon and google.maps.Polyline * * .GetPointAtDistance() returns a GLatLng at the specified distance * * along the path. * * The distance is specified in metres * * Reurns null if the path is shorter than that * * * *********************************************************************** * * * This Javascript is provided by Mike Williams * * Blackpool Community Church Javascript Team * * http://www.blackpoolchurch.org/ * * http://econym.org.uk/gmap/ * * * * This work is licenced under a Creative Commons Licence * * http://creativecommons.org/licenses/by/2.0/uk/ * * * *********************************************************************** * * * Version 1.1 6-Jun-2007 * * Version 1.2 1-Jul-2007 - fix: Bounds was omitting vertex zero * * add: Bearing * * Version 1.3 28-Nov-2008 add: GetPointsAtDistance() * * Version 1.4 12-Jan-2009 fix: GetPointsAtDistance() * * Version 3.0 11-Aug-2010 update to v3 * * * \*********************************************************************/ // === A method which returns a GLatLng of a point a given distance along the path === // === Returns null if the path is shorter than the specified distance === google.maps.Polygon.prototype.GetPointAtDistance = function(metres) { // some awkward special cases if (metres == 0) return this.getPath().getAt(0); if (metres < 0) return null; if (this.getPath().getLength() < 2) return null; var dist = 0; var olddist = 0; for (var i = 1; (i < this.getPath().getLength() && dist < metres); i++) { olddist = dist; dist += google.maps.geometry.spherical.computeDistanceBetween(this.getPath().getAt(i), this.getPath().getAt(i - 1)); } if (dist < metres) { return null; } var p1 = this.getPath().getAt(i - 2); var p2 = this.getPath().getAt(i - 1); var m = (metres - olddist) / (dist - olddist); return new google.maps.LatLng(p1.lat() + (p2.lat() - p1.lat()) * m, p1.lng() + (p2.lng() - p1.lng()) * m); } // === Copy all the above functions to GPolyline === google.maps.Polyline.prototype.GetPointAtDistance = google.maps.Polygon.prototype.GetPointAtDistance;

html, body, #map_canvas { height: 100%; width: 100%; margin: 0px; padding: 0px }
    

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.