Hello all,

I am trying to develop a typical hotel type app where the user can enter an address and get directions to the hotel. If they click another link they can get the directions with turn by turn maps. I have this working but it is slow. If you check out the results on the Marriott site it takes about 4-6 seconds to get the directions with maps. It takes my app around 10-18 seconds. About 4-5 seconds is used getting the directions and the main route map, the rest of this time is spent making the calls to get the urls for the images on the jsp page.

This is the code I use to get my route. fromLocation and toLocation are Location objects.

Code:
        
SegmentSpecification[] routeSegmentSpec = new SegmentSpecification[2];
        routeSegmentSpec[0] = new SegmentSpecification();
        Waypoint startWP = new Waypoint();
        startWP.setLocation(fromLocation);
        startWP.setName("Start");
        startWP.setSnap(SnapType.Normal);
        routeSegmentSpec[0].setWaypoint(startWP);

        routeSegmentSpec[1] = new SegmentSpecification();
        Waypoint endWP = new Waypoint();
        endWP.setLocation(toLocation);
        endWP.setName("End");
        endWP.setSnap(SnapType.Normal);
        routeSegmentSpec[1].setWaypoint(endWP);

        SegmentOptions routeOptions = new SegmentOptions();
        routeOptions.setCalculateDirectionMapView(Boolean.TRUE);//FALSE
        routeOptions.setCalculateSegmentMapView(Boolean.FALSE);//FALSE
        routeOptions.setPreference(SegmentPreference.Quickest);
        routeSegmentSpec[0].setOptions(routeOptions);
        routeSegmentSpec[1].setOptions(routeOptions);

        RouteSpecification routeSpec = new RouteSpecification();
        routeSpec.setDataSourceName(dsname);
        ArrayOfSegmentSpecification segmentSpecArr = new ArrayOfSegmentSpecification();
        segmentSpecArr.setSegmentSpecification(routeSegmentSpec);
        routeSpec.setSegments(segmentSpecArr); 

        Route route = routeService.calculateRoute(routeSpec);
Here is the code where I get the array of Direction objects:
Code:
            Direction[] directions = route.getItinerary().getSegments().getSegment(0).getDirections().getDirection();

            ImageFormat format = new ImageFormat();
            format.setHeight(new Integer(routeToVO.getMapImageHeight()));
            format.setWidth(new Integer(routeToVO.getMapImageWidth()));         


            MapOptions mapOptions = new MapOptions();
            mapOptions.setIsOverviewMap(new Boolean(routeToVO.getIsOverviewMap()));
            mapOptions.setStyle(MapStyle.fromString(routeToVO.getDefaultMapStyle()));
            mapOptions.setFontSize(MapFontSize.fromString(routeToVO.getFontSize()));
            mapOptions.setRouteHighlightColor(RouteHighlightColor.fromString(routeToVO.getRouteHighlightColor()));
            mapOptions.setConstructionDelayHighlightColor(RouteHighlightColor.fromString(routeToVO.getConstructionDelayHighlightColor()));
            mapOptions.setConstructionClosureHighlightColor(RouteHighlightColor.fromString(routeToVO.getConstructionClosureHighlightColor()));         
            mapOptions.setReturnType(MapReturnType.ReturnUrl);        

            mapOptions.setFormat(format);


            MapSpecification mapSpec = new MapSpecification();
            mapSpec.setRoute(route); 
            mapSpec.setDataSourceName(dsname);
            mapSpec.setOptions(mapOptions);

            ArrayOfMapImage mapImages = new ArrayOfMapImage();        
            mapImages.setMapImage(renderService.getMap(mapSpec).getMapImage());

            MapImage[] myMapImages = mapImages.getMapImage();

            String mapurl = mapImages.getMapImage(0).getUrl();         

            HashMap dirs = new HashMap();
            dirs.put("mapurl", mapurl);
            dirs.put("directions",  directions);
            dirs.put("route", route);
This is where I get the map urls on the jsp. I originally did it in the previous code but am currently testing on the jsp. I am looping through an ArrayList containing the Direction array. x is what would be the index of the Direction array through the loop.

Code:
            MapView[] mapView = new MapView[1];
            mapView[0] = route.getItinerary().getSegments().getSegment(0).getDirections().getDirection(x).getView().getByHeightWidth();
            ArrayOfMapView mapViewArray = new ArrayOfMapView();
            mapViewArray.setMapView(mapView);
  
            spec.setViews(mapViewArray);
  
            MapImage[] mapImages = renderService.getMap(spec).getMapImage();           
            for(int i = 0; i < mapImages.length; i++){
                MapImage mapImage = mapImages[i];
                map = mapImage.getUrl();               
            }
Any suggestions as to how I can optimize this to get the segment maps more quickly?

Thanks!