Recalculate Google Maps Direction if take the wrong lane - google-maps-api-3

I use the Google Maps Javascript API v3 for calculating the directions from my current position to my end destination in an iPad PhoneGap Application.
Now I want to make a function which automatically recalculates the directions, if you take the wrong lane. That means, I will make a marker for the current position on the map and then should check if it's near the directions-polygon, if not recalculate the route.
The directions are printed out in a canvas-element and I couldn't find anything how to compare it with my markers…
Any idea?

The following line works. Just set the tolerance as desired.
google.maps.geometry.poly.isLocationOnEdge (point, polyline, tolerance)
It will return true if point is located in the polyline/ polygen. Let me know if tyhis doesn't work.
axs

Related

How to code a pathfinding player in godot using A*?

Iam nooby in godot, I have to use A* to traslate the player to the goal position, but I do not know how to start, pls help!! basically I have just 2 tiles in the tilemap, 1 of them is allowed to pass over it, I have to extract I guess the allowed tile and calculate the distance between the position player with the position goal, getting the real distance and then check cell per cell which has the lowest cost, but I do not know how to do that :c
func get_player_init_pos():
var pos = map_to_world(Vector2(54,1))pos.y += half_cell_size.y
return pos
func is_tile_vacant(pos, direction):
var curr_tile = world_to_map(pos)
var next_tile = get_cellv(curr_tile + direction)
var next_tile_pos = Vector2()
if(next_tile == 0):
next_tile_pos = map_to_world(curr_tile + direction)
else:next_tile_pos = pos
return next_tile_pos
I have this, the first part of the code is to locate the player in the map and the second is for check the tile walls in the map
You could roll your own path finding algorithm. However, there is little point in doing so, since Godot has a AStar class you can use. However, you probably don't need to use that either, because Godot has a navigation system. And that is what I'm going to suggest you to use.
First of all, you can specify both navigation and collision polygons on your tiles. You need to have the navigation polygons. Go ahead and do them.
Second you want to have a Navigation2D in the scene tree and have your TileMap as a child.
And third, you can ask the Navigation2D for a path with get_simple_path, you pass the start and end positions as arguments and you get an array of points that make up the path.
Since you mention A*, I'll briefly explain using the AStar too anyway.
First, you need to add the cells with add_point. It requires ids. It is a good idea to be clever with the ids so you can compute the id for a given position. For example x * width + y if you know the size.
So you can iterate over the tiles in your TileMap and call add_point for each one (You don't need to add cell that are not passable).
Then you need to specify the connections with connect_points (it takes the ids of the points as parameters).
And finally you can call get_point_path passing the start and end ids. Again it gives you a array of points.

How to get nearest place?

I'm using the code below:
I want to get the nearest place from google (only need nearest result).
To do this, I changed radius but then result is wrong.
https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=6.384314,81.324417&radius=1000&types=accounting|airport|amusement_park|aquarium|art_gallery|atm|bakery|bank|bar|beauty_salon|bicycle_store|book_store|bowling_alley|bus_station|cafe|campground|car_dealer|car_rental|car_repair|car_wash|casino|cemetery|church|city_hall|clothing_store|convenience_store|courthouse|dentist|department_store|doctor|electrician|electronics_store|embassy|establishment|finance|fire_station|florist|food|funeral_home|furniture_store|gas_station|general_contractor|grocery_or_supermarket|gym|hair_care|hardware_store|health|hindu_temple|home_goods_store|hospital|insurance_agency|jewelry_store|laundry|lawyer|library|liquor_store|local_government_office|locksmith|lodging|meal_delivery|meal_takeaway|mosque|movie_rental|movie_theater|moving_company|museum|night_club|painter|park|parking|pet_store|pharmacy|physiotherapist|place_of_worship|plumber|police|post_office|real_estate_agency|restaurant|roofing_contractor|rv_park|school|shoe_store|shopping_mall|spa|stadium|storage|store|subway_station|synagogue|taxi_stand|train_station|trave_agency|university|veterinary_care|zoo&sensor=false&key=AIzaSyA0JD_Z2Uo2AfnDTejQFWHAXOIaRRpjF8c
Order the results by distance(by using the rankby-parameter):
https://maps.googleapis.com/maps/api/place/nearbysearch/json?rankby=distance&location=6.384314,81.324417&types=accounting|airport|......&sensor=false&key=AIzaSyA0JD_Z2Uo2AfnDTejQFWHAXOIaRRpjF8c
Note:
you must ommit the radius in this case
there is no way to limit the number of results to a specific value

Is there any built-in functions in Google Earth API to calculate the least camera range needed to show whole geoobject?

For example, I have a line with 3 points:
lat / lon
56,1 / 46,1
56,2 / 46,2
56,3 / 46,3
If I do:
var lookAt = ge.createLookAt('');
lookAt.setLatitude(56.2);
lookAt.setLongitude(46.2);
lookAt.setRange(5000.0);
For sure i will see all line, but from too far
If I do:
lookAt.setRange(10.0);
I will see only middle line point, so... Is there any way to calculate the least needed range to see whole line?
Try using the GEarthExtensions library script. In particular - computeBounds()
You can see an example of it here
http://earth-api-utility-library.googlecode.com/svn/trunk/extensions/examples/bounds-view.html

Google Maps API v3 Polylines not drawing

App works this way:
User enters a starting location and a distance. User can choose to draw circles, or lines over the roads. Circles work fine. Lines used to work.
When Lines, the code finds the lat/long of the starting location, then for the points N, S, E, W of the origin at the distance set by the user (say, 100km). Starting with the N destination, the code calls google.maps.DirectionsService() to get directions from the origin to N. This returns an array of lat/longs in the the route.overview_path.
NOTE: I COULD use the directionsRenderer() to draw the route, BUT, the distance drawn would be greater than the distance set by the user. Drawing the entire route from the origin to the point N might be 124km over the roads, and I just want to draw 100km.
Instead, I step through the route.overview_path[] array, checking the distance between that point and the point of origin, adding each point to a new array. When the distance is greater than the dist set by the user, I stop, pop off the last element, then create a new Polyline based on this 2nd, smaller array.
I've spent the entire day in Chrome's developer mode walking through the javascript, setting breakpoints, watching locals, etc. The array of points passed in google.maps.Polyline({}) is a good array of unique points. I just cannot figure out why they aren't rendering.
Ultimately, the code used to draw 4 lines starting at the point of origin, one heading North, one heading East, South, West. etc....
The code is here: http://whosquick.com/RunViz.html
Thank you for your attention.
Nevermind. Solved it.
var objGeo = new LatLon(Geo.parseDMS(myroute.overview_path[0].Pa), Geo.parseDMS(myroute.overview_path[0].Qa));
I had inadvertently switched Pa with Qa.

How to know how many mils are currently google map is showing

i have got center of map using map.getCenter(); and i got current zoom of google map using getZoom(); please tell me how can i calculate/get current show mils area in google map. i am using asp.net and javascript.
With GMap2.getBounds() you can get the visible rectangular region of the map view.
Then using these coordinates you can construct a GPolygon object and calculate the area in square meters using GPolygon.getArea() function. Then convert given area to mils (1 meter = 39 370.0787 mils).
the GLatLng object has a distanceFrom function that takes another GLatLng. The map has getBounds from which you'll be able to get the corners of interest, and check the distance between them.

Resources