-
Notifications
You must be signed in to change notification settings - Fork 48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error batch-geocoding a single query #147
Comments
After inspecting this more with @1ec5 there seem to be some more interesting things going on: The Mapbox Geocoding API returns different object types when batch geocoding one vs. many results, and it seems to be affecting how we parse out the responses. In this case, geocoding many addresses results in a returned array of many FeatureCollections. On the other hand, when batch geocoding one query, one FeatureCollection object is returned. I would have expected a batch geocoding query with more than one query to return an object containing multiple FeatureCollections instead of an array of FeatureCollections. Because of this, open func batchGeocode(_ options: GeocodeOptions & BatchGeocodeOptions, completionHandler: @escaping BatchCompletionHandler) -> URLSessionDataTask {
let url = urlForGeocoding(options)
let task = dataTaskWithURL(url, completionHandler: { (data) in
guard let data = data else { return }
let decoder = JSONDecoder()
do {
let result = try decoder.decode([GeocodeResult].self, from: data)
let placemarks = result.map { $0.placemarks }
let attributionsByQuery = result.map { $0.attribution }
completionHandler(placemarks, attributionsByQuery, nil)
} catch {
// ForwardBatchGeocodeOptions(query: "1 Main St")
// ForwardBatchGeocodeOptions(queries: ["1 Main St"])
completionHandler(nil, nil, error as NSError)
}
}) { (error) in
// ForwardBatchGeocodeOptions(queries: ["1 Main St", "2 Main St"])
completionHandler(nil, nil, error)
}
task.resume()
return task
} Internally, it seems like for all three of these queries mentioned in the above comments return the same |
If you call
Geocoder.batchGeocode(_:completionHandler:)
, passing in a BatchGeocodeOptions that has only one coordinate or query, the following error results:The following code in
Geocoder.urlForGeocoding(_:)
assumes a batch geocode must have more than one query, which isn’t necessarily the case:MapboxGeocoder.swift/MapboxGeocoder/MBGeocoder.swift
Lines 294 to 299 in 2dec3ec
A single-query batch ends up requesting from the normal
mapbox.places
mode instead ofmapbox.places-permanent
. The two modes have different response formats, so amapbox.places
response ends up getting parsed unsuccessfully as amapbox.places-permanent
response.Geocoder.urlForGeocoding(_:)
shouldn’t hard-code modes like this; it should be up to the options object to determine the mode that gets inserted into the URL./cc @captainbarbosa
The text was updated successfully, but these errors were encountered: