7 Replies Latest reply on Jun 12, 2009 10:05 AM by jfb00

    Create a Route

    jfb00 Level 3

      Hello All,

      Base on a list of addresses I need to create the best route for delivery starting point from the same address.

      I found this yahoo component:


      Base on the examples and the API I was able to found an address and set a market and maybe I can set all my list of addresses with markets.

      But how can create the best route?

      Any ideas? Thoughts? Maybe another component up there?

      I don't care about the map image display, it's only important the order of the route for the driver.

      Thanks for your help





      <?xml version="1.0" encoding="utf-8"?>
          Copyright (c) 2008 Yahoo! Inc.  All rights reserved. 
          The copyrights embodied in the content of this file are licensed under the BSD (revised) open source license
          <mx:UIComponent id="mapContainer" width="100%" height="100%"/>
                  import com.yahoo.maps.webservices.geocoder.GeocoderResultSet;
                  import com.yahoo.maps.webservices.geocoder.GeocoderResult;
                  import com.yahoo.maps.webservices.geocoder.events.GeocoderEvent;
                  import com.yahoo.maps.webservices.geocoder.Geocoder;
                  import com.yahoo.maps.api.markers.SearchMarker;
                  import com.yahoo.maps.webservices.local.LocalSearchItem;
                  import com.yahoo.maps.webservices.local.LocalSearchResults;
                  import com.yahoo.maps.api.markers.SimpleMarker;
                  import com.yahoo.maps.api.core.location.LatLon;
                  import com.yahoo.maps.api.core.location.BoundingBox;
                  import com.yahoo.maps.api.core.location.Address;
                  import com.yahoo.maps.api.YahooMapEvent;
                  import com.yahoo.maps.api.YahooMap;
                  import mx.controls.Alert;
                  import mx.events.ResizeEvent;
                  private var _yahooMap:YahooMap;
                  private var _geocoder:Geocoder;
                  private var _address:Address;
                  private var _address1:Address;
                  private function handleCreationComplete():void
                      // this examples uses an application id passed into the app via FlashVars.
                      // Get your own from the Yahoo! Developer Network @ http://developer.yahoo.com/wsregapp/
                      var appid:String = Application.application.parameters.appid;
                      appid='getYourID from yahoo';
                      // create YahooMap instance and listen for map initialize event
                      _yahooMap = new YahooMap();
                      _yahooMap.addEventListener(YahooMapEvent.MAP_INITIALIZE, handleMapInitialize);
                      _yahooMap.init(appid, mapContainer.width, mapContainer.height);
                  private function handleMapInitialize(event:YahooMapEvent):void
                      var marker:SimpleMarker = new SimpleMarker();
                      _address = new Address("8426 GreenTree, Alexandria, VA");
                         marker.address = _address;



        • 2. Re: Create a Route
          jfb00 Level 3

          Thanks for your reply and help.

          Looks like we can do more with Google maps.

          http://gmaps-samples-flash.googlecode.com/svn/trunk/articles/directions/Section4/Direction sDemo.html


          I have 15 addresses in an arrayCollection without order.

          How can I organize all addresses to create a good route?

          I will keep playing with this. I hope someone can give me an idea in how to accomplish this.




          • 3. Re: Create a Route
            RWinscot Level 1

            For the sake of the example... lets say you have three points: A, B, and C. A being your current location.


            1. Geocode each address in your list (e.g. lat/lon way points)

            2. Collect a series of GRoute objects for each permutation of your way points: A->B->C, A->C->B (remember A is your origin)

            3. Shuffle through the GRoute results and find the one with the shortest duration (GRoute.getDuration()) should be your guy...


            Just remember that GRoute.getDistance() might not be helpful... as the shortest distance might take you on roads with a 2 mph speed limit or have you ascending 10,000 vertical feet. Hmm... you might/could prompt the user before with a "shortest distance or fastest route?" option or give them the list back and let them choose.


            A word of warning... for a web-based Flash/Flex solution I wouldn't try to do any of this in local / client-side code. Messing around with line-segment data and all the characteristics (line type, number of lanes, speed limit, direction of traffic, etc) will probably give you gray hair.

            • 4. Re: Create a Route
              jfb00 Level 3

              Thanks for you reply and help!

              getDuration()... it's anything else like getDistance()?

              What about if I collect the info of the duration between each point with A?

              A -> B  10

              A -> C   8

              A -> D 20

              Then sort byt the result (The longest will be the last one to stop).

              Do you think it works?  i will start playing with this two ideas.




              • 5. Re: Create a Route
                RWinscot Level 1

                Some years back I worked for a very large school district that was trying to optimize bus routes... I found (very quickly) that balancing distance and duration is a tricky matter. It is not uncommon to find 'distance optimized' routes that leave you idling at busy intersections... one after the other. So... if you have duration data - make sure you cross-check your distances assumptions.


                Also, I apologize... I was in Google Maps mode when I was responding to your post. The Yahoo Maps Flash API doesn't have (as far as I am aware) a direct analog to Google's GRoute and will leave you trying to calculate distance as the crow flies between two geocoded points. The greater the distance between your points the more error prone that approach may be; all roads are not straight and the longer the road the more earth's curve comes into play. You might be able to massage things a bit by mixing in some traffic data...

                • 6. Re: Create a Route
                  jfb00 Level 3

                  Hi Natasha,

                  How can I do multiple stops?

                  Perhaps 4 direccions.




                  • 7. Re: Create a Route
                    jfb00 Level 3

                    Hi All,

                    I got all markets in place and now I can calcualte multiple address distance and duration base on my A point.

                    The sort has to be duration then distance.

                    Now I will create the route between the addresses and maybe I can post this sample for future referece.

                    Thanks for all you help.