Search results
Top results related to google maps driving directions from current location
Top Answer
Answered Feb 23, 2013 · -2 votes
What you expect to be the users location is not what you expect, "current location" will be taken by google as any other address, and google tries to find a place that matches the query.
When somebody told you that "current location" will force google to resolve the location of the user, this is wrong.
You may geolocate the user on your own and then create the link based on the geolocation-result.
Other Answers
Answered Dec 19, 2017 · 197 votes
For those still looking, here are some methods of linking to Google Maps:
Spaces can be changed to + or encoded as %20.
https://www.google.com/maps?q=760+West+Genesee+Street+Syracuse+NY+13204-
https://www.google.com/maps?daddr=760+West+Genesee+Street+Syracuse+NY+13204-
https://www.google.com/maps?saddr=760+West+Genesee+Street+Syracuse+NY+13204&daddr=314+Avery+Avenue+Syracuse+NY+13204-
https://www.google.com/maps?saddr=My+Location&daddr=760+West+Genesee+Street+Syracuse+NY+13204-
https://www.google.com/maps?saddr=My+Location&daddr=43.12345,-76.12345-
https://www.google.com/maps?ll=43.12345,-76.12345&q=food&z=14-
https://www.google.com/maps?saddr=My+Location&daddr=Pinckney+Hugo+Group-
- ["Linking to a location (No directions)","",""," https://www.google.com/maps?q=760+West+Genesee+Street+Syracuse+NY+13204"," ",""]
- ["No starting point (User input required to generate directions).","",""," https://www.google.com/maps?daddr=760+West+Genesee+Street+Syracuse+NY+13204"," ",""]
- ["With a set location as starting point (Automatically generates directions with no user input required).","",""," https://www.google.com/maps?saddr=760+West+Genesee+Street+Syracuse+NY+13204&daddr=314+Avery+Avenue+Syracuse+NY+13204"," ",""]
- ["With \"My Location\" as starting point (Automatically generates directions with no user input required).","",""," https://www.google.com/maps?saddr=My+Location&daddr=760+West+Genesee+Street+Syracuse+NY+13204"," ",""]
- ["Current Location to Latitude and Longitude","",""," https://www.google.com/maps?saddr=My+Location&daddr=43.12345,-76.12345"," ",""]
- ["Query search of a Latitude and Longitude. Also shows setting a default zoom level.","",""," https://www.google.com/maps?ll=43.12345,-76.12345&q=food&z=14"," ",""]
- ["String search as destination","",""," https://www.google.com/maps?saddr=My+Location&daddr=Pinckney+Hugo+Group"," ",""]
Here is a post I made that I will keep updated as there are some even newer ways to do this!
Other Answers
Answered Dec 09, 2019 · 15 votes
The answers of GreatBlakes and Jon Alslund-Lanthén suggest a way that sometimes gives you the right result but that can fail if the language of your user isn't English.
As of 2019, the best way seems to be:
https://www.google.com/maps/dir/?api=1&destination=Googleplex,+1600+Amphitheatre+Pkwy
1/5
Top Answer
Answered Mar 24, 2021 · 1 votes
It's a new open source library which provides many cool features out-of-the-box. Specifically with directions, probably the coolest feature is allowing developers to use their overlays (e.g. markers, polygons, etc.) directly as places and waypoints, alongside many other flexible types. No more manual labor...
Here's an example from the docs:
<bs-google-map *bsSafe ...> <bs-google-maps-marker [position]="someCoord" #marker="marker"></bs-google-maps-marker> <bs-google-maps-polygon [path]="somePath" #polygon="polygon"></bs-google-maps-polygon> <bs-google-maps-directions [through]="[marker, polygon, 'Jerusalem', [31.9, 34.7], { lat: 31.99, lng: 35 }, 'Tel Aviv']"></bs-google-maps-directions></bs-google-map>
Full directions docs | npm package | Official site & demos
2/5
Top Answer
Answered Feb 03, 2019 · 0 votes
I'm not sure what the issue was that was preventing you from realising your goals - I tried the code above and it appeared to work - as it was too cold to work in the garage I had a little play and created a small demo; perhaps though you or someone else might find the following useful?
Initially when the call to navigator.getCurrentLocation resolves with the user's location the map loads using the returned position object to form the map centre location. The route to the pre-defined destination is then calculated using the Directions service with a modified options parameter - notably in this instance to hide the default markers. The reason for hiding the markers is because they do not expose any events and thus we cannot bind any listeners to them so we add our own. The added markers allow the route to be dynamically re-calculated ( can also drag the actual route itself )
The text version of the directions is available by clicking on one of the two markers.
The destination is in Birmingham, UK. If you are outwith the UK this might not work immediately without editing this location. Also, a valid API key is required.
<!DOCTYPE html><html> <head> <title>Google Maps: Directions from my location to...</title> <meta charset='utf-8' /> <style> body, html { height:100%;margin:0;padding:0;box-sizing:border-box; } #map { width:100%;height:100vh; margin:auto;float:none; } #info{ display:none;padding:0.25rem;margin:1rem;background:white;font-size:0.75rem!important; } </style> <script> let map; let marker; let infoWindow; let oDir; let oTraf; let oDisp; let oReq; let destination={ lat:52.477068, lng:-1.911663 }; const modes={ walk:'WALKING', bike:'BICYCLING', car:'DRIVING', pub:'TRANSIT' }; const advReqOptions={ provideRouteAlternatives:true, optimizeWaypoints:true, avoidFerries:true, avoidHighways:false, avoidTolls:false }; function initMap(){ /* utility to add a new marker and assign listeners to it */ const addmarker=function( pos, type, colour ){ marker=new google.maps.Marker({ icon:'//maps.google.com/mapfiles/ms/icons/'+colour+'-pushpin.png', type:type, draggable:true, position:pos, map:map }); google.maps.event.addListener( marker, 'click', function(e){ infoWindow.getContent().style.display='block'; infoWindow.setPosition( this.getPosition() ); infoWindow.open( map ); }); google.maps.event.addListener( marker, 'dragend', calculateroute ); }; /* callback function when markers are dragged and the route is re-calculated */ const calculateroute=function(e){ oReq={ origin:this.type=='start' ? e.latLng : oReq.origin, destination:this.type=='finish' ? e.latLng : oReq.destination, travelMode:modes.car }; oDir.route( Object.assign( oReq, advReqOptions ), callback ); }; /* process the route response */ const callback=function(r,s){ if( s === 'OK' ) oDisp.setDirections( r ); else evtGeoFailure( s ); } /* Main callback invoked when the user's location has been identified */ const evtGeoSuccess=function(p){ /* create the map */ let location={ lat: parseFloat( p.coords.latitude ), lng: parseFloat( p.coords.longitude ) }; let options= { zoom: 16, center:location, mapTypeId: google.maps.MapTypeId.ROADMAP }; let routeoptions={ suppressMarkers:true, draggable:true, map:map }; /* create the map object */ map = new google.maps.Map( document.getElementById('map'), options ); /* add draggable markers to the start and end of pre-defined route */ addmarker( location, 'start', 'grn' ); addmarker( destination, 'finish', 'red' ); /* display the textual directions in an infowindow which opens on marker click */ infoWindow = new google.maps.InfoWindow({ maxWidth:450, disableAutoPan:false }); infoWindow.setContent( document.getElementById('info') ); /* create the objects required for the directions calculations */ oDir=new google.maps.DirectionsService(); oDisp=new google.maps.DirectionsRenderer( routeoptions ); oTraf=new google.maps.TrafficLayer(); /* construct the initial request */ oReq={ origin:location, destination:destination, travelMode:modes.car }; /* go get the directions... */ oDisp.setMap( map ); oTraf.setMap( map ); oDisp.setPanel( infoWindow.getContent() ); oDir.route( Object.assign( oReq, advReqOptions ), callback ); }; const evtGeoFailure=function(e){ console.info( 'you broke the internets: %s', e ) }; const config={ maximumAge:60000, timeout:5000, enableHighAccuracy:true }; if( navigator.geolocation ) navigator.geolocation.getCurrentPosition( evtGeoSuccess, evtGeoFailure, config ); } </script> <script src='//maps.googleapis.com/maps/api/js?key=<<APIKEY>>&callback=initMap' async defer></script> </head> <body> <div id='map'></div> <div id='info'></div> </body></html>
3/5
Top Answer
Answered Jul 26, 2013 · 2 votes
Here's an update of your existing code:
// Executes in UI thread, after the parsing process@Overrideprotected void onPostExecute(List<List<HashMap<String, String>>> result) { if (result.size() < 1) { Toast.makeText(getActivity(), "No Points", Toast.LENGTH_SHORT).show(); return; } TextView tv1 = (TextView) getActivity().findViewById(R.id.location1); TextView tv2 = (TextView) getActivity().findViewById(R.id.location2); TextView tv3 = (TextView) getActivity().findViewById(R.id.location3); TextView tv4 = (TextView) getActivity().findViewById(R.id.location4); TextView[] views = {tv1, tv2, tv3, tv4}; // Traversing through all the routes for (int i = 0; i < result.size(); i++) { // Fetching i-th route List<HashMap<String, String>> path = result.get(i); String distance = "No distance"; // Fetching all the points in i-th route for (int j = 0; j < path.size(); j++) { HashMap<String, String> point = path.get(j); if (j == 0) { distance = point.get("distance"); continue; } } // Set text views[i].setText(distance); }}
This code makes a not-so-good assumption: It assumes that the size of result is the same size as views, which in your case should be 4. When you run this code, you may get an IndexOutOfBounds error if you have more than 4 results (which shouldn't happen). Eventually you will want to verify that the size of result is 4, or the number of TextView's you have. If you have any questions or this doesn't work right, just let me know :)
EDIT: To get all distances at once, you can modify your DownloadTask to take in multiple URL's.
Change class definition:
private class DownloadTask extends AsyncTask<String, Void, ArrayList<String>>-
This says that your background operation will return a list of String's.
Modified doInBackground(), which now can process multiple URL's:
// Downloading data in non-ui thread@Overrideprotected ArrayList<String> doInBackground(String... urlList) { try { ArrayList<String> returnList = new ArrayList<String>(); for(String url : urlList) { // Fetching the data from web service String data = Locations.this.downloadUrl(url); returnList.add(data); } return returnList; } catch (Exception e) { Log.d("Background Task", e.toString()); return null; // Failed, return null }}
Then you onPostExecute() becomes
// Executes in UI thread, after the execution of// doInBackground()@Overrideprotected void onPostExecute(ArrayList<String> results) { super.onPostExecute(results); ParserTask parserTask = new ParserTask(); // Invokes the thread for parsing the JSON data parserTask.execute(results);}
Now, you will have to modify your ParserTask code to take in a list of JSON Strings, and not just one JSON String. Just change your ParserTask input parameters and put everything inside a for loop to loop through each JSON String. You will also have to modify the parameter of onPostExecute() to take in a List of whatever is there already, so that way it doesn't process one result, but a list of results. I can't show you those modifications here because it would be way too long, and then there would be no challenge for you :)
EDIT TWO: In getLastLocation() you're only calling DownloadTask with one URL, but you should put four URL's like this downloadTask.execute(url1, url2, url3, url4). Also, since ParserTask still only processes one JSON String, you should take out the four TextView's and the array looping out of the onPostExecute(). To tell the ParserTask which TextView to populate, add a constructor to ParserTask which takes in a TextView as a parameter. Then make an instance variable within ParserTaskthat is assigned in the constructor and used in onPostExecute() to display the distance.
Then, take that TextView array stuff I gave you before and put it in the onPostExecute() of DownloadTask. When you loop through the String results, also loop through the TextView array and pass in the TextView in the ParserTask constructor.
Basically, you're adding a constructor in the ParserTask to tell it which TextView to draw on. When your DownloadTask is finished, you pass it the right TextView for the URL. For example, R.id.location3 for the third URL.
4/5
Also try
5/5
play.google.com › store › appsGoogle Maps - Apps on Google Play
play.google.com › store › appsMay 17, 2024 · Get real-time GPS navigation, traffic, and transit info, and explore local neighborhoods by knowing where to eat, drink and go - no matter what part of the world you’re in. Get there faster with...
www.geeksforgeeks.org › how-to-find-your-travelHow to Find your Travel Direction in Google Maps
www.geeksforgeeks.org › how-to-find-your-travelMay 2, 2024 · Step 1: Open Google Maps on your device. Open the Google Maps application on your Android device. Open Google Maps on your device. Step 2: Search Destination. Search for the destination in the search box and select the location. Search Destination. Step 3: Select Directions. On the left, you can see Directions in the blue box. Click it.
www.pocket-lint.com › google-maps-vs-wazeGoogle Maps vs Waze: Which is really better? - Pocket-lint
www.pocket-lint.com › google-maps-vs-wazeMay 22, 2024 · Both apps allow you to select a destination and will then generate driving directions to that destination from your current location as determined by your phone. It's also possible to set a...
www.lifewire.com › alternate-route-plan-googleHow to Plan an Alternate Route With Google Maps - Lifewire
www.lifewire.com › alternate-route-plan-googleMay 16, 2024 · Your own route: Click along the blue line and drag that point anywhere. Keep doing this to plan a new route. A Google alternate: Select an alternate gray route line. It will turn blue, indicating it's the new preferred route. Multiple destinations: Add a destination > press + Add destination below it to add another > repeat.
www.youtube.com › watchHow To Use Google Map While Driving | Google Maps Driving ...
www.youtube.com › watchMay 19, 2024 · From launching the app to entering your destination and following turn-by-turn directions, this guide covers all the necessary steps to help you navigate seamlessly while on the road. Ensure a ...
- 1 min
- 29
- QuickFix Masters
www.ncesc.com › geographic-pedia › how-do-i-getHow do I get directional directions on Google Maps? - NCESC
www.ncesc.com › geographic-pedia › how-do-i-get6 days ago · To get directional directions on Google Maps, follow these steps: 1. Search for your destination or tap it on the map. 2. In the bottom left, tap Directions. 3. Choose your mode of transportation. For Driving, Transit, or other options, you can also save your favorite trips by tapping on the Pin icon. How do I turn on the compass in Google Maps?
www.tomsguide.com › how-to › how-to-see-traffic-infoHow to see traffic info on Google Maps | Tom's Guide
www.tomsguide.com › how-to › how-to-see-traffic-info5 days ago · Open Google Maps. (Image: © Future) Go to google.com/maps. If you want to check a specific location or area, enter that location or area in the search bar, otherwise just proceed to...
Searches related to google maps driving directions from current location