So Ive implemented a searchBar
for my maps application and its giving me some weirds results. If I search for "Oslo" for instance, it points me to a very specific but weird spot north of the city and zoomed far in. There must be something I've done wrong in code here. Anyone able to spot the issue?
// When user submits search query
func searchBarSearchButtonClicked(searchBar: UISearchBar){
// resign first responder and dismiss the searchbar.
searchBar.resignFirstResponder()
dismissViewControllerAnimated(true, completion: nil)
// Create and start search request
localSearchRequest = MKLocalSearchRequest()
localSearchRequest.naturalLanguageQuery = searchBar.text
localSearch = MKLocalSearch(request: localSearchRequest)
localSearch.startWithCompletionHandler { (localSearchResponse, error) -> Void in
if localSearchResponse == nil{
let alertController = UIAlertController(title: nil, message: "Place Not Found", preferredStyle: UIAlertControllerStyle.Alert)
alertController.addAction(UIAlertAction(title: "Dismiss", style: UIAlertActionStyle.Default, handler: nil))
self.presentViewController(alertController, animated: true, completion: nil)
return
}
let center = CLLocationCoordinate2D(latitude: localSearchResponse!.boundingRegion.center.latitude, longitude: localSearchResponse!.boundingRegion.center.longitude)
self.updateCurrentMapRegion(center, distance: 5000)
NSNotificationCenter.defaultCenter().postNotificationName("LocationUpdate", object: nil, userInfo: ["latitude": center.latitude, "longitude": center.longitude])
}
}
Also, one issue is that I've hardcoded the distance to 5000 meters when updating the map region after getting a search result. How can I handle this in a more dynamic manner?
Whats the alternative to using MKLocalSearchRequest() which in my mind sounds like something you should use when looking for stuff nearby and not larger entities such as cities, etc.