i used googlemap direction api draw multiple location's route. use postman check response status, , can check 200 ok. problem when use alamofire, response failure!
when draw origin destination, response ok.(always) if add additional location, alamofire return failure.
someone has same problem , solve it?


below code. thanx!
originaddress = locationinfolist[0] destinationaddress = locationinfolist.last var waypointurl:string = "" var waypoint = locationinfolist.dropfirst() waypoint = waypoint.droplast() coordinate in waypoint { print("~~~~") let waypoint = "|\(coordinate.latitude),\(coordinate.longitude)" waypointurl.append(waypoint) print("~xxxxxxx~~~") print(waypointurl) print("xxxxxxx") } directionurl = "https://maps.googleapis.com/maps/api/directions/json?" + "origin=\(originaddress.latitude),\(originaddress.longitude)&destination=\(destinationaddress.latitude),\(destinationaddress.longitude)&waypoints=optimize:true\(waypointurl)" + "&key=apikey" print("vvvvvvv") print(directionurl) print("vvvvvvvv") } alamofire.request(directionurl, method: .post, parameters: nil, encoding: jsonencoding.default, headers: nil).responsejson { (response) in print(response) if let json = response.result.value { print(json) let mapresponse: [string: anyobject] = json as! [string : anyobject] let routesarray = (mapresponse["routes"] as? array) ?? [] let routes = (routesarray.first as? dictionary<string, anyobject>) ?? [:] let overviewpolyline = (routes["overview_polyline"] as? dictionary<string,anyobject>) ?? [:] let polypoints = (overviewpolyline["points"] as? string) ?? "" let line = polypoints self.addpolyline(encodedstring: line) } } }
it seems sending parameters in url , using json encoding. change jsonencoding.default urlencoding.defaultfor encoding parameter of alamofire request.
also google map api docs, says follows. believe, url encoding solve issue.
each waypoint can either place name, address, or comma-separated latitude/longitude coordinates. strings should url-escaped, waypoints such "berlin,germany|paris,france" should converted berlin%2cgermany%7cparis%2cfrance.
Hi, I have same problem,
ReplyDeletei have two wcf service with two different url but same config,
Postman works ok with two url
but Alamofire with one url is ok and other return error 400