Search code examples
iosswiftgoogle-mapsalamofire

Google maps directions


I want to show routing on the google map, but I get this error

I call this api only once, but at the first time I get this error

What should i do ?

"OVER_QUERY_LIMIT"

let url = "https://maps.googleapis.com/maps/api/directions/json?origin=\(origin)&destination=\(destination)&mode=driving"

    Alamofire.request(url).responseJSON { response in
        //print(response.request as Any)  // original URL request
        //print(response.response as Any) // HTTP URL response
        //print(response.data as Any)     // server data
        //print(response.result as Any)   // result of response serialization

        let json = try! JSON(data: response.data!)
        let routes = json["routes"].arrayValue
        print(json)
        // print route using Polyline

        DispatchQueue.global(qos: .default).async(execute: {() -> Void in
            // Do something...
            DispatchQueue.main.async(execute: {() -> Void in
                // self.hideHUD()
            })
        })
        for route in routes
        {
            let routeOverviewPolyline = route["overview_polyline"].dictionary
            let points = routeOverviewPolyline?["points"]?.stringValue
            let path = GMSPath.init(fromEncodedPath: points!)
            let polyline = GMSPolyline.init(path: path)
            polyline.strokeWidth = 4
            polyline.strokeColor = #colorLiteral(red: 0, green: 0.4784313725, blue: 1, alpha: 1)
            polyline.map = self.mapView

        }

Solution

  • Beginning September 10, 2018, usage for self-serve customers in Brazil, Canada, and India will be limited to $200/month. This situation is temporary. Please see the Maps FAQ for more details. A new pay-as-you-go pricing plan is now in effect for the Google Maps Platform APIs.

    Understanding Billing for Maps, Routes, and Places