locked
google maps directions walking RRS feed

  • Question

  • User-319370498 posted

    Hi I'm making a mobile website, I have integrated a api for finding a route to a location. But googlemaps gives the directions for a car, and I need it for walkers.

    Can someone help me?

    Friday, August 19, 2011 10:22 AM

Answers

  • User-287874541 posted

    Sorry about that - there are different forms of Google Maps APIs. Well it took me awhile to figure it out, but I think I found the solution.

    Look at this line:

    self.directions.load(ft);

    Try changing it to:

    self.directions.load(ft, {travelMode:G_TRAVEL_MODE_WALKING});

    Really not sure, but that seems to be how to do it. Let me know how it goes!

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, August 19, 2011 2:28 PM

All replies

  • User1932525027 posted

    TravelMode.WALKING

    Some of this documentation may help you: http://code.google.com/apis/maps/documentation/javascript/services.html

    Friday, August 19, 2011 11:03 AM
  • User-319370498 posted

    Thanks, now I need to know what code I have to place in my file to change the driving to walking.

     

    Friday, August 19, 2011 1:27 PM
  • User-287874541 posted

    Thanks, now I need to know what code I have to place in my file to change the driving to walking.

    It seems like all you need to do is add this to the API call:

    &mode=walking

    If this doesn't work or you need more help, let me know!

    Friday, August 19, 2011 1:30 PM
  • User-319370498 posted

    Thanks, now I need to know what code I have to place in my file to change the driving to walking.

    It seems like all you need to do is add this to the API call:

    &mode=walking

    If this doesn't work or you need more help, let me know!

    Sorry but I don't know where the api call is, I'm kind of a newby :p

    Friday, August 19, 2011 1:46 PM
  • User683681608 posted

    I have integrated the driving directions from this website: http://www.haiders.net/post/GoogleMaps-Driving-Directions-API-Wrapper-Control-for-ASPNET.aspx.

    The API key find it in GoogleDrivingDirections.ascx. Where can I join '&mode=walkin'? This is the source code from GoogleDrivingDirections.ascx

    <%@ Control Language="C#" ClassName="GoogleDrivingDirections" %>
    <%--
    Created by: Abu Haider - www.haiders.net
    First published: 2/14/2008
    Last Update: 2/15/2008 - Changed to Ajax API loader
    
    FileName: GoogleDrivingDirections.ascx
    Required files:none
    Description:
    ASP.NET Wrapper control for Google Driving Directions API.
    It loads driving directions in a div element of its own.
    Optionally loads a synchronized map showing the route in another div element.
    
    Assign valid addresses to the FromAddress and ToAddress properties.
    To load directions on page load automatically, set the AutoLoad Property = True;
    
    No API Key is needed for running on localhost, but must be provided for production Website.
    Assign a valid Key to the APIKey property. 
    API Keys can be freely obtained from http://code.google.com
    API Keys are issued for a specific host name, so you will need a Key
    every time you publish the website to a new host.
    
    To display the Map along with directions, create a div element on the page and set width and height through css/style
    Then assign the ID of this div element to the MapElementID of this control.
    
    Visit www.haiders.net for more information. Limited support via the blog is available.
    
    *** Use at your own risk and thoroughly test in your production environment ***
     
    --%>
    <script runat="server">
        private Unit width, height;
        private string fromAddress, toAddress;
        private string mapElementID = string.Empty;
        private bool autoLoad = true;
        
        //Api Key related
        private string apikey = string.Empty;
        const string apikey_localhost = "***";
        const string api_include = "http://www.google.com/jsapi?key={0}" ;
    
        public bool AutoLoad
        {
            get { return autoLoad; }
            set { autoLoad = value; }
        }
    
        public string APIKey
        {
            get { return apikey; }
            set { apikey = value; }
        }
        
        
        public string MapElementID
        {
            get { return mapElementID; }
            set { mapElementID = value; }
        }
        
        public Unit Width
        {
            get { return width; }
            set { width = value; Directions.Style[HtmlTextWriterStyle.Width] = width.ToString(); }    
        }
    
        public Unit Height
        {
            get { return height; }
            set { height = value; Directions.Style[HtmlTextWriterStyle.Height] = height.ToString(); }
        }
        
        public string FromAddress
        {
            get { return fromAddress; }
            set { fromAddress = value; }
        }
    
        public string ToAddress
        {
            get { return toAddress; }
            set { toAddress = value; }
        }
        
        protected override void OnPreRender(EventArgs e)
        {
            string apiURL = null;
            if (Request.Url.IsLoopback)
                apiURL = string.Format(api_include, apikey_localhost);
            else
            {
                if (apikey.Length > 0) //if an api key is specified
                    apiURL = string.Format(api_include, apikey);
                else
                {
                    Directions.InnerHtml = "You need to specifiy a Google API key for this host: " + Request.Url.Host;
                }
            }
            
            if (apiURL != null)
            {
                Page.ClientScript.RegisterClientScriptInclude(this.GetType(), "API_KEY_REFERENCE", apiURL);
    
                //if (toAddress.Length > 0 && fromAddress.Length > 0) //We can render directions
                //   Page.ClientScript.RegisterStartupScript(this.GetType(), "DD_LOAD", "_nco_dd.loadDirections();", true);
                
            }
                
            base.OnPreRender(e);
        }
        
    </script>
    <div runat="server" id="Directions">
    <strong>GoogleMaps Driving Directions</strong><br />
    No api key is needed for running it on localhost.<br />
    But you will need an api key for the production URL.<br />
    You may obtain a key from code.google.com<br />
    </div>
    
    <script type="text/javascript">
    //<![CDATA[
        
        function _nco_gdir()
        {
            this.fromAddress = "<%=fromAddress%>";
            this.toAddress = "<%=toAddress%>";
            this.mapElementID = "<%=mapElementID%>";
            this.autoLoad = "<%=autoLoad.ToString().ToLower() %>";
            this.directions = null;
            var self = this; //don't ask
            google.load("maps","2"); //load version 2 of GoogleMaps API
    
            this.handleErrors = function()
            {
                
                if(self.divMap) self.divMap.innerHTML = "";
                if (self.directions && self.directions.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
                {
                    alert("Driving directions are not available for the address you entered.\nThis may be because the from address is relatively new, or it may be incorrect.");                
                }
                else
                {
                    alert("We are currently unable to display directions for the specified addresses.");
                }
            };
                    
            this.loadDirections = function()
            {
                if(!self.directions)
                {
                    if(self.mapElementID.length>0)
                    {
                        self.divMap = document.getElementById(self.mapElementID);
                        
                        if(self.divMap!=null)
                        {
                            self.dirMap = new google.maps.Map2(self.divMap);
                            //self.dirMap.addControl(new google.maps.LargeMapControl());					    
                            //self.dirMap.addControl(new google.maps.ScaleControl());        
                        }
                        else
                            self.dirMap = null;
                    }
                    
                    self.dirpanel = document.getElementById("<%=Directions.ClientID%>");
                    self.directions = new google.maps.Directions(self.dirMap, self.dirpanel);
                                    google.maps.Event.addListener(self.directions, "error", self.handleErrors);
                }
                
                //Clear Directions, if any
                self.dirpanel.innerHTML = "";
    
                //if(this.divMap!=null)
                   // this.divMap.innerHTML = "Loading Map... Please wait";
                
                var ft = "from: " +  self.fromAddress + " to: " + self.toAddress;
                    
                self.directions.load(ft);
                
            };
            
            if(this.fromAddress.length>0 && this.toAddress.length>0 && this.autoLoad)
                google.setOnLoadCallback(this.loadDirections); //The google way to register to window.onload
        }
        
        _nco_dd = new _nco_gdir();
                
    //]]>
    </script>         
    

     

    Friday, August 19, 2011 1:53 PM
  • User683681608 posted

    I work with lordplazikovbj5 ;)

    Friday, August 19, 2011 1:55 PM
  • User-287874541 posted

    Sorry about that - there are different forms of Google Maps APIs. Well it took me awhile to figure it out, but I think I found the solution.

    Look at this line:

    self.directions.load(ft);

    Try changing it to:

    self.directions.load(ft, {travelMode:G_TRAVEL_MODE_WALKING});

    Really not sure, but that seems to be how to do it. Let me know how it goes!

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, August 19, 2011 2:28 PM
  • User-319370498 posted

    Sorry about that - there are different forms of Google Maps APIs. Well it took me awhile to figure it out, but I think I found the solution.

    Look at this line:

    self.directions.load(ft);

    Try changing it to:

    self.directions.load(ft, {travelMode:G_TRAVEL_MODE_WALKING});

    Really not sure, but that seems to be how to do it. Let me know how it goes!

    thanks man, you made my day :D.

    Hero !

    Friday, August 19, 2011 2:35 PM
  • User-287874541 posted

    No problem! Glad it actually worked :) Let me know if you need any more help!

    Friday, August 19, 2011 2:39 PM
  • User683681608 posted

    thanks for the solution and for your great tip!

    Friday, August 19, 2011 2:41 PM