[英]Google Maps not showing route when building from latitude and longitude values
[英]finding latitude and longitude between a route in google maps
我在這個問題上感到非常震驚。 我有一組緯度,經度,價格詳細信息,如json。 我正在使用Google Maps 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
是否放置在折線上(或附近)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.