diff --git a/README.md b/README.md index 782c8dc..0680e7b 100644 --- a/README.md +++ b/README.md @@ -133,6 +133,10 @@ Sets the center of the map. `animated` property defaults to `true`. Shows the user's location on the map. +#### look_up_location(CLLocation) { |placemark, error| } + +This method takes a CLLocation object and will return one to many CLPlacemark to represent nearby data. + ##### iOS 8 Location Requirements iOS 8 introduced stricter location services requirements. You are now required to add a few key/value pairs to the `Info.plist`. Add these two lines to your `Rakefile` (with your descriptions, obviously): diff --git a/lib/ProMotion/map/map_screen_module.rb b/lib/ProMotion/map/map_screen_module.rb index b0a585c..2309a12 100644 --- a/lib/ProMotion/map/map_screen_module.rb +++ b/lib/ProMotion/map/map_screen_module.rb @@ -242,6 +242,16 @@ def look_up_address(args={}, &callback) return geocoder.geocodeAddressString(args[:address].to_s, inRegion:args[:region].to_s, completionHandler: callback) if args[:region] end + def look_up_location(location, &callback) + if location.kind_of?(CLLocation) + geocoder = CLGeocoder.new + geocoder.reverseGeocodeLocation(location, completionHandler: callback) + else + PM.logger.info("You're trying to reverse geocode something that isn't a CLLocation") + callback.call nil, nil + end + end + ########## Cocoa touch methods ################# def mapView(map_view, viewForAnnotation:annotation) annotation_view(map_view, annotation) diff --git a/spec/func_map_screen_spec.rb b/spec/func_map_screen_spec.rb index 3746a3c..47253a6 100644 --- a/spec/func_map_screen_spec.rb +++ b/spec/func_map_screen_spec.rb @@ -241,4 +241,20 @@ def add_image_annotation map_screen.map.isRotateEnabled.should == false end + it "can lookup a location" do + location = CLLocation.alloc.initWithLatitude(-34.226082, longitude: 150.668374) + + map_screen.look_up_location(location) do |placemarks, fetch_error| + @error = fetch_error + @placemark = placemarks.first + resume + end + + wait do + @error.should == nil + @placemark.should.be.kind_of?(CLPlacemark) + @error = nil + @placemark = nil + end + end end