Search the Community
Showing results for tags 'Google API'.
-
Привет всем! Такая проблема, как по нажатию кнопки сделать построение маршрута от метро Берестейка к определенному адресу (адрес известен) ?. <button class="route btn btn-primary" id="travelMode1" data-travelmode="WALKING">Пешком</button> <button class="route btn btn-primary" id="travelMode2" data-travelmode="DRIVING">На авто</button> function initialize() { var settings = { zoom: 17, center: new google.maps.LatLng(50.445068, 30.420486), mapTypeControl: true, mapTypeControlOptions: { style: google.maps.MapTypeControlStyle.DROPDOWN_MENU }, navigationControl: true, navigationControlOptions: { style: google.maps.NavigationControlStyle.SMALL }, mapTypeId: google.maps.MapTypeId.ROADMAP }; var map = new google.maps.Map(document.getElementById("map_canvas"), settings); //————————————————— var travelMode; // var travelMode = "google.maps.DirectionsTravelMode.WALKING"; var modeButton1 = document.getElementById('travelMode1'); var modeButton2 = document.getElementById('travelMode2'); modeButton1.onclick = function() { travelMode = "google.maps.DirectionsTravelMode."+this.getAttribute('data-travelmode'); modeButton2.className = ''; this.className = 'active'; setRoutetype (); } modeButton2.onclick = function() { travelMode = "google.maps.DirectionsTravelMode."+this.getAttribute('data-travelmode'); modeButton1.className = ''; this.className = 'active'; setRoutetype (); } //——————————————-- var balloon = new google.maps.InfoWindow(); var service = new google.maps.DirectionsService(); var direction = new google.maps.DirectionsRenderer({map: map}); var position = new google.maps.LatLng(50.448238, 30.491260); var request = { origin: position, destination: latlng, travelMode: travelMode }; var companyImage = new google.maps.MarkerImage('design/images/contacts/pin-jaya.png', new google.maps.Size(154, 133), new google.maps.Point(0, 0), new google.maps.Point(60, 120) ); var companyPos = new google.maps.LatLng(50.448238, 30.491260); var companyMarker = new google.maps.Marker({ position: companyPos, map: map, icon: companyImage, title: "JayaDigital", zIndex: 3 }); function setRoutetype () { navigator.geolocation.getCurrentPosition(function(position) { showRouteService(position); }); } function showRouteService(position) { var request = { origin: new google.maps.LatLng(position.coords.latitude, position.coords.longitude), destination: latlng, travelMode: google.maps.DirectionsTravelMode.DRIVING }; service.route(request, function(response, status) { if (status == google.maps.DirectionsStatus.OK) { direction.setDirections(response); } }); } }