MKDirections Calculate Over Limit

Hi.

I want to draw a route for more than one location. When I make a request with the following codes, it gives an error after 50 calculations.

Is there such a limit? I did not see it in the documents.


func drawPolyline(coordinates: [CLLocationCoordinate2D]){
     let coords= coordinates.count - 1

     for i in 1...coords{
          let request = MKDirectionsRequest()
          let loc1 = coordinates[i - 1]
          let loc2 = coordinates[i]

          request.source = MKMapItem(placemark: MKPlacemark(coordinate: loc1))
          request.destination = MKMapItem(placemark: MKPlacemark(coordinate: loc2))
          request.transportType = .automobile

          let direction= MKDirections(request: request)
          direction.calculate(completionHandler: {

               response, error in if error == nil {
                    let myRoute= response!.routes[0] as MKRoute
                    self.mkMap.add(myRoute.polyline)
                }
          })
     }
}

What is the exact error message you get ?


There is a limit for reverse geocoding ; may be the same ?

See reverseGeocodeLocation

After initiating a reverse-geocoding request, do not attempt to initiate another reverse- or forward-geocoding request. Geocoding requests are rate-limited for each app, so making too many requests in a short period of time may cause some of the requests to fail. When the maximum rate is exceeded, the geocoder passes an error object with the value

network
to your completion handler.


Found some indication from Apple on what this rate limit is:

h ttps://forums.developer.apple.com/thread/20499

I have also found the limit to be about 50 stops. In my app, if a user has more than 50 stops, I tell them to wait a full minute and then try again starting from stop 51. That seems to work.

Accepted Answer

Then we may have determined that there is a limit of will in one go. This limit is 50. Also, your solution is logical, but I only need to run the entire route.

MKDirections Calculate Over Limit
 
 
Q