gpt4 book ai didi

javascript - 在谷歌地图中查找路线之间的经纬度

转载 作者:行者123 更新时间:2023-11-30 17:21:11 31 4
gpt4 key购买 nike

我在这个问题上很吃惊。我有一组纬度、经度、价格详细信息作为 json。我正在使用谷歌地图 DirectionsService。我需要找到给定路线上的纬度和经度。我用 json 细节绘制标记。我需要找到路线上方的纬度和经度。有了这个结果,我需要找到它的价格。我正在使用下面的代码。对不起我的英语不好。提前致谢

<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false&libraries=places"></script>
<div class = 'map_div'>
<div id="map-canvas" style="float:left;width:100%;"></div>
</div>
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
<script>
var toll_details = '[{"id":"1","latitude":"-23.413133333","longitude":"-46.36105","price":"4.2"},{"id":"2","latitude":"-23.413133333","longitude":"-46.36105","price":"4.2"},{"id":"3","latitude":"-22.930330555","longitude":"-45.360716666","price":"10.1"},{"id":"4","latitude":"-22.495041666","longitude":"-44.569480555","price":"10.1"},{"id":"5","latitude":"-22.495041666","longitude":"-44.569480555","price":"10.1"},{"id":"6","latitude":"-22.716169444","longitude":"-43.716736111","price":"10.1"},{"id":"7","latitude":"-22.716169444","longitude":"-43.716736111","price":"10.1"},{"id":"8","latitude":"-22.716169444","longitude":"-43.716736111","price":"10.1"},{"id":"9","latitude":"-22.716169444","longitude":"-43.716736111","price":"10.1"},{"id":"10","latitude":"-22.930330555","longitude":"-45.360716666","price":"10.1"},{"id":"11","latitude":"-23.338847222","longitude":"-46.150333333","price":"4.5"},{"id":"30","latitude":"-21.547725","longitude":"-45.241530555","price":"1.5"},{"id":"31","latitude":"-21.000197222","longitude":"-44.966825","price":"1.5"},{"id":"32","latitude":"-20.591744444","longitude":"-44.701375","price":"1.5"},{"id":"33","latitude":"-20.268288888","longitude":"-44.423925","price":"1.5"},{"id":"34","latitude":"-23.322011111","longitude":"-46.581397222","price":"1.5"},{"id":"35","latitude":"-22.907088888","longitude":"-46.423438888","price":"1.5"},{"id":"511","latitude":"-20.830697222","longitude":"-51.504008333","price":"4.2"}]';
var all_tolls = JSON.parse(toll_details);

var directionsDisplay;
var directionsService = new google.maps.DirectionsService();
var map, response, marker;
var options = {
types: ['(cities)'],
componentRestrictions: {country: 'br'}
};


function initialize() {
directionsDisplay = new google.maps.DirectionsRenderer();
var mapOptions = {
zoom: 6,
center: new google.maps.LatLng(-23.5500, -46.6333)
}
map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);

calcRoute();

directionsDisplay.setMap(map);
}

function finding(all_tolls) {
for (i = 0; i < all_tolls.length; i++) {
var marker = new google.maps.Marker({
position: new google.maps.LatLng(all_tolls[i].latitude, all_tolls[i].longitude),
map: map
});
}
}

function calcRoute() {
var start = 'São Paulo, Brazil';
var end = 'Rio de Janeiro, Brazil';

var waypts = [];

var request = {
origin: start,
destination: end,
waypoints: waypts,
optimizeWaypoints: true,
travelMode: google.maps.TravelMode.DRIVING,
unitSystem: google.maps.UnitSystem.METRIC
};
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response);

}
});
finding(all_tolls)
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
<style>
html, body, #map-canvas {
height: 100%;
margin: 0px;
padding: 0px
}
.map_div {
border: 1px solid #CCCCCC;
border-radius: 4px;
float: left;
height: 500px;
margin-left: 4px;
margin-top: 10px;
padding: 10px;
width: 700px;
}
</style>

最佳答案

根据返回的路径(例如在 overview_path 上)创建折线,然后遍历 all_tolls 并使用 google.maps.geometry.poly.isLocationOnEdge检查给定的 LatLng 是否位于折线上(或附近)。

关于javascript - 在谷歌地图中查找路线之间的经纬度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25112363/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com