Re: tsp.AddAdress() does not work, with tsp.AddWaypoint() it works

275 views
Skip to first unread message

Geir Kokkvoll Engdahl

unread,
May 18, 2013, 4:52:46 AM5/18/13
to google-maps...@googlegroups.com
What you are doing should not work even with addWaypoint. You need to
move tsp.getOrder() and tsp.getDurations() into the onSolveCallback
function. The call to tsp.solveRoundTrip is asynchronous (so it
returns before the computation is done). The results are not ready
until onSolveCallback is called.

Geir

On Fri, May 17, 2013 at 3:22 PM, Cannect <kee...@cannect.nl> wrote:
> Hello all,
>
> Thanks for taking the time for me. The title describes it well, the setup
> below works only with tsp.AddWaypoint(). Possible my adresses are wrong?
> For me it is most important to get the trip order and total trip duration.
>
> var myOptions = {
> zoom: 12,
> center: new google.maps.LatLng(52.119999,5.866699),
> mapTypeId: google.maps.MapTypeId.ROADMAP
> };
> myMap = new google.maps.Map(document.getElementById("map"),
> myOptions);
>
> directionsPanel = document.getElementById("routebeschrijving");
>
> tsp = new BpTspSolver(myMap, directionsPanel);
>
> tsp.setTravelMode(google.maps.DirectionsTravelMode.DRIVING);
>
> tsp.addAddress('Amsterdam, the netherlands');
> tsp.addAddress('ede, the netherlands');
> tsp.addAddress('arnhem, the netherlands');
> tsp.addAddress('Groningen, the netherlands');
>
> tsp.solveRoundTrip(onSolveCallback);
>
> var order = tsp.getOrder();
> var durations = tsp.getDurations();
> console.log(order);
> console.log(durations);
>
> }
>
> function onSolveCallback(theTsp){
> }
> function addWaypointCallback(theTsp){
> }
>
>
> Thanks in advance!
>
> --
> You received this message because you are subscribed to the Google Groups
> "Google Maps TSP Solver" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to google-maps-tsp-s...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

Cannect

unread,
May 23, 2013, 10:56:08 AM5/23/13
to google-maps...@googlegroups.com
Hi, many thanks it is working now. Strange that it did work with the addWayPoint method fired first.

Op zaterdag 18 mei 2013 10:52:46 UTC+2 schreef geir het volgende:
> email to google-maps-tsp-solver+unsub...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages