Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function route() {
- // Clear any previous route boxes from the map
- clearBoxes();
- // Convert the distance to box around the route from miles to km
- distance = parseFloat(document.getElementById("distance").value) * 1.609344;
- var request = {
- origin: "Surabaya",
- destination: "Sidoarjo",
- travelMode: google.maps.DirectionsTravelMode.DRIVING
- }
- // Make the directions request
- directionService.route(request, function(result, status) {
- if (status == google.maps.DirectionsStatus.OK) {
- directionsRenderer.setDirections(result);
- // Box around the overview path of the first route
- var path = result.routes[0].overview_path;
- var boxes = routeBoxer.box(path, distance);
- drawBoxes(boxes);
- findPlaces(boxes);
- } else {
- alert("Directions query failed: " + status);
- }
- });
- }
- // Draw the array of boxes as polylines on the map
- function drawBoxes(boxes) {
- boxpolys = new Array(boxes.length);
- for (var i = 0; i < boxes.length; i++) {
- boxpolys[i] = new google.maps.Rectangle({
- bounds: boxes[i],
- fillOpacity: 0,
- strokeOpacity: 1.0,
- strokeColor: '#000000',
- strokeWeight: 1,
- map: map
- });
- }
- }
- // Clear boxes currently on the map
- function clearBoxes() {
- if (boxpolys != null) {
- for (var i = 0; i < boxpolys.length; i++) {
- boxpolys[i].setMap(null);
- }
- }
- boxpolys = null;
- }
- //placing a marker on the map
- function createMarker(map, coords, title) {
- var marker = new google.maps.Marker({
- position: coords,
- map: map,
- title: title,
- draggable: false,
- icon: image
- });
- return marker;
- }
- //Search places having coordinates inside the boxes
- function findPlaces(boxes) {
- $.getJSON('proses.php', function(results){
- console.log(results);
- for (var i = 0; i < boxes.length; i++) {
- $.each(results, function(k, v){
- if ( v.lat < boxes[i].getNorthEast().lat() && v.lat > boxes[i].getSouthWest().lat() && v.lng > boxes[i].getSouthWest().lng() && v.lng < boxes[i].getNorthEast().lng()) {
- var coords = new google.maps.LatLng(v.lat, v.lng);
- createMarker(map, coords, v.nama);
- }
- });
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment