Skip to content

Instantly share code, notes, and snippets.

Created December 1, 2016 06:35
Show Gist options
  • Save anonymous/83beee5fad2a4b2b804da614913aef6c to your computer and use it in GitHub Desktop.
Save anonymous/83beee5fad2a4b2b804da614913aef6c to your computer and use it in GitHub Desktop.
JS Bin isLocationOnEdge // source https://jsbin.com/hivuyu
<!DOCTYPE html>
<html>
<head>
<meta name="description" content="isLocationOnEdge">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyDfKLDQPQgpVU7wokCKnUgJVEB8vcwmd3g&libraries=geometry">
</script>
<title>JS Bin</title>
<style id="jsbin-css">
#map{
width: 80%;
height: 300px;
}
</style>
</head>
<body>
<h2> Hello man this is good</h2>
<div id="map"></div>
<script id="jsbin-javascript">
console.clear();
var directionsService = new google.maps.DirectionsService();
var polyline = null;
var Locations = {
"driver": [
{
"location": {
"start": {
"formatted_address": "Oberoi Mall General AK Vidya Marg, Yashodham, Goregaon, Mumbai, Maharashtra 400063, India",
"lat": 19.173808,
"lng": 72.8605943
},
"end": {
"formatted_address": "Pune, Maharashtra, India",
"lat": 18.5204303,
"lng": 73.85674369999992
}
}
}
],
"passenger": [
{
"location": {
"start": {
"formatted_address": "Chhatrapati Shivaji International Airport Area, Vile Parle, Mumbai, Maharashtra 400099, India",
"lat": 19.0895595,
"lng": 72.86561440000003
},
"end": {
"formatted_address": "Pune, Maharashtra, India",
"lat": 18.5204303,
"lng": 73.85674369999992
}
}
}
]
};
function initialize() {
var directionsDisplay = new google.maps.DirectionsRenderer();
var kandivali = new google.maps.LatLng(19.2048, 72.8368);
var lonavala = new google.maps.LatLng(18.7481, 73.4072);
var khandala = new google.maps.LatLng(18.7548, 73.3778);
var lavasa = new google.maps.LatLng(18.4077, 73.5075);
var blore = new google.maps.LatLng(12.9716, 77.5946);
var mapOptions = {
zoom: 10,
mapTypeId: 'roadmap'
};
var map = new google.maps.Map(document.getElementById('map'),
mapOptions);
directionsDisplay.setMap(map);
var request = {
origin: new google.maps.LatLng(Locations.driver[0].location.start),
destination: new google.maps.LatLng( Locations.driver[0].location.end),
// Note that Javascript allows us to access the constant
// using square brackets and a string value as its
// "property."
travelMode: google.maps.TravelMode['DRIVING']
};
directionsService.route(request, function(response, status) {
if (status == 'OK') {
directionsDisplay.setDirections(response);
polyline = google.maps.geometry.encoding.decodePath(response.routes[0].overview_polyline);
polyline = new google.maps.Polyline({path: polyline});
console.log(google.maps.geometry.poly.isLocationOnEdge(lonavala, polyline, 0.01));
if (google.maps.geometry.poly.isLocationOnEdge(lonavala, polyline, 0.05)) {
alert("lonavala is on way!");
}
if (google.maps.geometry.poly.isLocationOnEdge(kandivali, polyline, 0.05)) {
alert("kandivali is on way ");
}
if (google.maps.geometry.poly.isLocationOnEdge(khandala, polyline, 0.05)) {
alert("khandala is on way ");
}
if (google.maps.geometry.poly.isLocationOnEdge(lavasa, polyline, 0.05)) {
alert("lavasa is on way ");
} else {
alert("lavasa is not on way ");
}
if (google.maps.geometry.poly.isLocationOnEdge(blore, polyline, 0.1)) {
alert("blore is on way!");
} else {
alert("blore is not on way ");
}
}
});
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
<script id="jsbin-source-css" type="text/css">#map{
width: 80%;
height: 300px;
}</script>
<script id="jsbin-source-javascript" type="text/javascript">
console.clear();
var directionsService = new google.maps.DirectionsService();
var polyline = null;
var Locations = {
"driver": [
{
"location": {
"start": {
"formatted_address": "Oberoi Mall General AK Vidya Marg, Yashodham, Goregaon, Mumbai, Maharashtra 400063, India",
"lat": 19.173808,
"lng": 72.8605943
},
"end": {
"formatted_address": "Pune, Maharashtra, India",
"lat": 18.5204303,
"lng": 73.85674369999992
}
}
}
],
"passenger": [
{
"location": {
"start": {
"formatted_address": "Chhatrapati Shivaji International Airport Area, Vile Parle, Mumbai, Maharashtra 400099, India",
"lat": 19.0895595,
"lng": 72.86561440000003
},
"end": {
"formatted_address": "Pune, Maharashtra, India",
"lat": 18.5204303,
"lng": 73.85674369999992
}
}
}
]
};
function initialize() {
var directionsDisplay = new google.maps.DirectionsRenderer();
var kandivali = new google.maps.LatLng(19.2048, 72.8368);
var lonavala = new google.maps.LatLng(18.7481, 73.4072);
var khandala = new google.maps.LatLng(18.7548, 73.3778);
var lavasa = new google.maps.LatLng(18.4077, 73.5075);
var blore = new google.maps.LatLng(12.9716, 77.5946);
var mapOptions = {
zoom: 10,
mapTypeId: 'roadmap'
};
var map = new google.maps.Map(document.getElementById('map'),
mapOptions);
directionsDisplay.setMap(map);
var request = {
origin: new google.maps.LatLng(Locations.driver[0].location.start),
destination: new google.maps.LatLng( Locations.driver[0].location.end),
// Note that Javascript allows us to access the constant
// using square brackets and a string value as its
// "property."
travelMode: google.maps.TravelMode['DRIVING']
};
directionsService.route(request, function(response, status) {
if (status == 'OK') {
directionsDisplay.setDirections(response);
polyline = google.maps.geometry.encoding.decodePath(response.routes[0].overview_polyline);
polyline = new google.maps.Polyline({path: polyline});
console.log(google.maps.geometry.poly.isLocationOnEdge(lonavala, polyline, 0.01));
if (google.maps.geometry.poly.isLocationOnEdge(lonavala, polyline, 0.05)) {
alert("lonavala is on way!");
}
if (google.maps.geometry.poly.isLocationOnEdge(kandivali, polyline, 0.05)) {
alert("kandivali is on way ");
}
if (google.maps.geometry.poly.isLocationOnEdge(khandala, polyline, 0.05)) {
alert("khandala is on way ");
}
if (google.maps.geometry.poly.isLocationOnEdge(lavasa, polyline, 0.05)) {
alert("lavasa is on way ");
} else {
alert("lavasa is not on way ");
}
if (google.maps.geometry.poly.isLocationOnEdge(blore, polyline, 0.1)) {
alert("blore is on way!");
} else {
alert("blore is not on way ");
}
}
});
}
google.maps.event.addDomListener(window, 'load', initialize);
</script></body>
</html>
#map{
width: 80%;
height: 300px;
}
console.clear();
var directionsService = new google.maps.DirectionsService();
var polyline = null;
var Locations = {
"driver": [
{
"location": {
"start": {
"formatted_address": "Oberoi Mall General AK Vidya Marg, Yashodham, Goregaon, Mumbai, Maharashtra 400063, India",
"lat": 19.173808,
"lng": 72.8605943
},
"end": {
"formatted_address": "Pune, Maharashtra, India",
"lat": 18.5204303,
"lng": 73.85674369999992
}
}
}
],
"passenger": [
{
"location": {
"start": {
"formatted_address": "Chhatrapati Shivaji International Airport Area, Vile Parle, Mumbai, Maharashtra 400099, India",
"lat": 19.0895595,
"lng": 72.86561440000003
},
"end": {
"formatted_address": "Pune, Maharashtra, India",
"lat": 18.5204303,
"lng": 73.85674369999992
}
}
}
]
};
function initialize() {
var directionsDisplay = new google.maps.DirectionsRenderer();
var kandivali = new google.maps.LatLng(19.2048, 72.8368);
var lonavala = new google.maps.LatLng(18.7481, 73.4072);
var khandala = new google.maps.LatLng(18.7548, 73.3778);
var lavasa = new google.maps.LatLng(18.4077, 73.5075);
var blore = new google.maps.LatLng(12.9716, 77.5946);
var mapOptions = {
zoom: 10,
mapTypeId: 'roadmap'
};
var map = new google.maps.Map(document.getElementById('map'),
mapOptions);
directionsDisplay.setMap(map);
var request = {
origin: new google.maps.LatLng(Locations.driver[0].location.start),
destination: new google.maps.LatLng( Locations.driver[0].location.end),
// Note that Javascript allows us to access the constant
// using square brackets and a string value as its
// "property."
travelMode: google.maps.TravelMode['DRIVING']
};
directionsService.route(request, function(response, status) {
if (status == 'OK') {
directionsDisplay.setDirections(response);
polyline = google.maps.geometry.encoding.decodePath(response.routes[0].overview_polyline);
polyline = new google.maps.Polyline({path: polyline});
console.log(google.maps.geometry.poly.isLocationOnEdge(lonavala, polyline, 0.01));
if (google.maps.geometry.poly.isLocationOnEdge(lonavala, polyline, 0.05)) {
alert("lonavala is on way!");
}
if (google.maps.geometry.poly.isLocationOnEdge(kandivali, polyline, 0.05)) {
alert("kandivali is on way ");
}
if (google.maps.geometry.poly.isLocationOnEdge(khandala, polyline, 0.05)) {
alert("khandala is on way ");
}
if (google.maps.geometry.poly.isLocationOnEdge(lavasa, polyline, 0.05)) {
alert("lavasa is on way ");
} else {
alert("lavasa is not on way ");
}
if (google.maps.geometry.poly.isLocationOnEdge(blore, polyline, 0.1)) {
alert("blore is on way!");
} else {
alert("blore is not on way ");
}
}
});
}
google.maps.event.addDomListener(window, 'load', initialize);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment