From 09be142a54807d60ebc5b6b6dec204a0d3bece00 Mon Sep 17 00:00:00 2001 From: Will Raxworthy Date: Tue, 10 Feb 2015 10:38:37 +1100 Subject: [PATCH 1/2] Add reverse geocoding for a location. --- lib/ProMotion/map/map_screen_module.rb | 5 +++++ spec/func_map_screen_spec.rb | 16 ++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/lib/ProMotion/map/map_screen_module.rb b/lib/ProMotion/map/map_screen_module.rb index b0a585c..a479bd7 100644 --- a/lib/ProMotion/map/map_screen_module.rb +++ b/lib/ProMotion/map/map_screen_module.rb @@ -242,6 +242,11 @@ 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) + geocoder = CLGeocoder.new + geocoder.reverseGeocodeLocation(location, completionHandler: callback) + 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 From ba1f2c0ee1188ccb04da26a42a7990073dc05878 Mon Sep 17 00:00:00 2001 From: Will Raxworthy Date: Tue, 10 Feb 2015 11:31:14 +1100 Subject: [PATCH 2/2] Add warning for incorrect object and update readme. --- README.md | 4 ++++ lib/ProMotion/map/map_screen_module.rb | 9 +++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) 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 a479bd7..2309a12 100644 --- a/lib/ProMotion/map/map_screen_module.rb +++ b/lib/ProMotion/map/map_screen_module.rb @@ -243,8 +243,13 @@ def look_up_address(args={}, &callback) end def look_up_location(location, &callback) - geocoder = CLGeocoder.new - geocoder.reverseGeocodeLocation(location, completionHandler: 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 #################