0% found this document useful (0 votes)
2 views

javascript - Google Maps Api check if place is on the route - Stack Overflow

The document discusses how to check if specific points of interest are located on a route generated using the Google Maps API. It provides a method using the 'isLocationOnEdge' function to determine if points fall within a specified tolerance of a polyline representing the route. The document includes code snippets and examples for implementing this functionality.

Uploaded by

Norman Kamaru
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

javascript - Google Maps Api check if place is on the route - Stack Overflow

The document discusses how to check if specific points of interest are located on a route generated using the Google Maps API. It provides a method using the 'isLocationOnEdge' function to determine if points fall within a specified tolerance of a polyline representing the route. The document includes code snippets and examples for implementing this functionality.

Uploaded by

Norman Kamaru
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

About Products For Teams Search… Log in Sign up

Home Google Maps Api check if place is on the route Ask Question

PUBLIC Asked 8 years, 10 months ago Modified 5 years, 6 months ago Viewed 7k times

Questions
I made with Google Maps an route between two places. Thats works fine.
Tags The Overflow Blog

Users 3 But i also have an database with interesting points on different roads in my country. I like to show
When to use gRPC vs GraphQL
them if they are on the generated route. Places who are not one this route, don't need to be shown.
Companies From Twitter Bootstrap to VP of
My database with intereseting points contains latitude and longitude coordinates. Engineering at Patreon, a chat with
COLLECTIVES Utkarsh...

Explore Collectives How can i check is they are on my route? There are approximately 30 or 40 interesting point in my
Featured on Meta
database.
TEAMS
Inbox improvements are live
// set request
Stack Overflow for var request = { Help us identify new roles for community
Teams – Start origin: initialLocation, members
collaborating and destination: destination,
sharing organizational travelMode: google.maps.TravelMode.DRIVING 2022 Community Moderator Election
knowledge. }; Results

The [collapse] tag is being burninated


// make route
directionsService.route(request, function(response, status) { Help needed: a call for volunteer reviewers
for the Staging Ground beta test
if (status == google.maps.DirectionsStatus.OK) {

// set route Linked


JoinCreate
Stack Overflow
a free Team to find the best answerdirectionsDisplay.setDirections(response);
to your technical question, help
Sign up with email Sign up with Google Sign up with GitHub Sign up with Facebook
othersWhy
answer
Teams?theirs. 23 How to to Get Places (e.g Gas Stations)
} along Route Between Origin and
Destination in Google Maps API
});
Related
UPDATE: Build new function "isLocationOnEdge". But the check runs the markers when they are
315 How can I check whether Google Maps is
not on the road: fully loaded?

$.ajax({ 442 Google Maps API v3: How to remove all


type: "POST", markers?
async:false,
url: base_url+"advies/get/9", 571 How to disable mouse scroll wheel scaling
success: function (data) { with Google Maps API
var result = jQuery.parseJSON(data);
3 Google Maps V3 Route Destination Mark
Edit
// loop trough flitsers
$.each(result.flitsers.m, function(i, item) { 715 Google Maps JS API v3 - Simple Multiple
Marker Example
// latitude longitude
var latlng = item["@attributes"].gps.split(","); 1107 What is the difference between angular-
route and angular-ui-router?
// make google latlng
var myLatlng = new google.maps.LatLng(latlng[0],latlng[1]); 2 SVG icon marker doesn't display in IE11,
iPad
if (myLatlng,coords)
{ 0 Update latitude and longitude
// set and define the marker overview_path google maps
var marker = new google.maps.Marker({
0 multiple marker doesn't show up in google
position: myLatlng,
map using angualrjs
map: map,
size: new google.maps.Size(15, 15),
icon: image, Hot Network Questions
title: 'Flitser'
}); Order of evaluation in v != std::exchange(v,
} predecessor(v))

Does a stunned Aasimar fall when flying with


});
Divine Soul?
}
}); Friends girlfriend's parents preventing her from
returning to UK from the UAE (Abu-Dhabi)
});
How can I figure out measurements/distances and
} hyperspace jump time in my universe that is
simple enough for readers to understand?

Should you pronounce the normally silent 'e'


javascript google-maps before a consonant in French poetry?

Why not use radio to communicate with ramp


marshall instead of marshalling signals?

Share Follow edited Jan 10, 2014 at 7:01 asked Jan 7, 2014 at 15:05 Proving ownership of a pseudonym

JelleP Am I legally obliged to honor requests made


966 7 20 38 outside the license file?

What do you call it when someone sings a melody


and simultaneously plays the exact same melody?
Add the interesting places to an array. Then for each coord in the route polyline, check it against the array of Can a person be fired, banned and evicted (etc.)
interesting places. – Andy Jan 7, 2014 at 15:13 without a court order?

possible duplicate of How to to Get Places (e.g Gas Stations) along Route Between Origin and Destination in The contradictions between agile approach and
Google Maps API, use your database instead of the places API. – geocodezip Jan 7, 2014 at 15:39 the growth of individual team member

Accuracy score of my KNN model is constant as k


Thanks for comments! The answer below is an example of your answers i guess. – JelleP Jan 8, 2014 at 7:00 increases?

Where are you using isLocationOnEdge ? How does your program know when to place a marker on the Is it believable that a civilization is governed under
one country?
line? – Tyler Eich Jan 10, 2014 at 21:06
If I add a misrepresentation clause to 3-clause BSD
new google.maps.Marker creates the marker. The var is only to store the marker in a later stadium. – JelleP license would it remain GPL-compatible?
Jan 13, 2014 at 6:56
Generalization of Chinese remainder theorem to
non-normal subgroups
Add a comment
How do you simulate resistor noise with LTSpice?

2 Answers Sorted by: Highest score (default) Why do most of my games have graphics errors
on my Windows ME retro PC?

Is there a list of all "Inconsistencies" in WH40k?


isLocationOnEdge(point:LatLng, poly:Polygon|Polyline, tolerance?:number)
Where would a string break if an instantaneous
UNEQUAL tensile force is applied on the ends?
3 To determine whether a point falls on or near a polyline, or on or near the edge of a polygon, pass
the point, the polyline/polygon, and optionally a tolerance value in degrees to What would be a recommended interest rate for
an unsecured loan to individuals with mediocre
google.maps.geometry.poly.isLocationOnEdge(). The function returns true if the distance between credit rating and income close to expenses?
the point and the closest point on the line or edge falls within the specified tolerance. The default QGIS: fill a simple line polygon with color when
tolerance value is 10-9 degrees. selected

Is it considered kidnapping if a teenager willingly


https://developers.google.com/maps/documentation/javascript/geometry runs away with someone else?

KDF aftertaste?
Share Follow answered May 11, 2017 at 13:43
True/False ACF field returning null by default even
Felix Kirathe if default value is true
41 4

Add a comment Question feed

Include the geometry library in your Google Maps API request:

1 http://maps.googleapis.com/maps/api/js?
v=3.exp& libraries=geometry &sensor=TRUE_OR_FALSE

Pseudo-code:

// Make isLocationOnEdge easier to access


var isLocationOnEdge = google.maps.geometry.poly.isLocationOnEdge;

for (var i = 0; i < interestingPlaces.length; i++) {


if (isLocationOnEdge(interestingPlaces[i],
response.routes[0].overview_path))
{
// Do something with interestingPlaces[i]
}
}

Google maps documentation for isLocationOnEdge()

Share Follow edited Jan 7, 2014 at 20:41 answered Jan 7, 2014 at 16:15
Tyler Eich
4,219 3 21 44

Thank your for the comment! This is what i search for. I only get one error rightnow. Did it like: myLatlng =
new google.maps.LatLng(latlng[0],latlng[1]); if
(isLocationOnEdge(myLatlng,response.routes[0].overview_path)) { } error: "TypeError: b.get is not a function"
– JelleP Jan 8, 2014 at 6:58

1 It's hard to say without more code, but it looks like new google.maps.LatLng(latlng[0],
latlng[1]) is your problem. It appears that you are sending two latLng s to create a new latLng . The
API requires two numbers. So google.maps.LatLng(Number, Number) should be better. – Tyler Eich
Jan 8, 2014 at 12:34

I added some code in my question. My error is solved but the script doesn't work yet. – JelleP Jan 10, 2014
at 7:03

Add a comment

Your Answer

Sign up or log in Post as a guest


Name
Sign up using Google

Sign up using Facebook Email


Required, but never shown

Sign up using Email and Password

Post Your Answer By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged javascript google-maps or ask
your own question.

STACK OVERFLOW PRODUCTS COMPANY STACK EXCHANGE NETWORK Blog Facebook Twitter LinkedIn Instagram

Questions Teams About Technology


Help Advertising Press Culture & recreation
Collectives Work Here Life & arts
Talent Legal Science
Privacy Policy Professional
Terms of Service Business
Contact Us
API
Cookie Settings
Data Site design / logo © 2022 Stack Exchange Inc; user contributions
Cookie Policy licensed under CC BY-SA. rev 2022.11.29.43061

You might also like