ProMotion-map 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +95 -6
- data/lib/ProMotion/map/map_screen_annotation.rb +9 -4
- data/lib/ProMotion/map/map_screen_module.rb +71 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4fa9190c3b59430b670b821061b1e100bca8a170
|
4
|
+
data.tar.gz: 68afd534d7381b9814866693a00dbd09f39ad65a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1378133321b46f3bdf9d36aad3c4a07dcc89195a56db40e412a30d9a6f0583c17f3e7dbc4a629821df4265bcb28d99b7272c575f6aed3a4cf5988c44f0b76f65
|
7
|
+
data.tar.gz: 25a582239c97133ac7027dbe71f52f1bb05b50c440c615f667708f706dd090bcbe4fbfacda512a8492162db66e4a2f61ee77dd96387bd99d280084b446a46147
|
data/README.md
CHANGED
@@ -21,6 +21,7 @@ Easily create a map screen, complete with annotations.
|
|
21
21
|
class MyMapScreen < PM::MapScreen
|
22
22
|
title "My Map"
|
23
23
|
start_position latitude: 35.090648651123, longitude: -82.965972900391, radius: 4
|
24
|
+
tap_to_add
|
24
25
|
|
25
26
|
def annotation_data
|
26
27
|
[{
|
@@ -54,8 +55,7 @@ class MyMapScreen < PM::MapScreen
|
|
54
55
|
your_param: "CustomWhatever",
|
55
56
|
action: :show_forest
|
56
57
|
}, {
|
57
|
-
|
58
|
-
latitude: 35.090648651123,
|
58
|
+
coordinate: CLLocationCoordinate2DMake(35.090648651123, -82.965972900391)
|
59
59
|
title: "Rainbow Falls",
|
60
60
|
subtitle: "Nantahala National Forest",
|
61
61
|
image: UIImage.imageNamed("custom-pin"),
|
@@ -91,8 +91,13 @@ All possible properties:
|
|
91
91
|
|
92
92
|
```ruby
|
93
93
|
{
|
94
|
-
|
95
|
-
|
94
|
+
# REQUIRED -or- use :coordinate
|
95
|
+
longitude: -82.956244328014,
|
96
|
+
latitude: 35.085548421623,
|
97
|
+
|
98
|
+
# REQUIRED -or- use :longitude & :latitude
|
99
|
+
coordinate: CLLocationCoordinate2DMake(35.085548421623, -82.956244328014)
|
100
|
+
|
96
101
|
title: "Stairway Falls", # REQUIRED
|
97
102
|
subtitle: "Gorges State Park",
|
98
103
|
image: "my_custom_image",
|
@@ -103,7 +108,7 @@ All possible properties:
|
|
103
108
|
}
|
104
109
|
```
|
105
110
|
|
106
|
-
You may pass whatever properties you want in the annotation hash, but `:longitude
|
111
|
+
You may pass whatever properties you want in the annotation hash, but (`:longitude` && `:latitude` || `:coordinate`), and `:title` are required.
|
107
112
|
|
108
113
|
Use `:image` to specify a custom image. Pass in a string to conserve memory and it will be converted using `UIImage.imageNamed(your_string)`. If you pass in a `UIImage`, we'll use that, but keep in mind that there will be another unnecessary copy of the UIImage in memory.
|
109
114
|
|
@@ -131,7 +136,22 @@ Sets the center of the map. `animated` property defaults to `true`.
|
|
131
136
|
|
132
137
|
#### show_user_location
|
133
138
|
|
134
|
-
Shows the user's location on the map.
|
139
|
+
Shows the user's location on the map. Must be called in the view initialization sequence on `will_appear` or _after_.
|
140
|
+
|
141
|
+
#### look_up_location(CLLocation) { |placemark, error| }
|
142
|
+
|
143
|
+
This method takes a CLLocation object and will return one to many CLPlacemark to represent nearby data.
|
144
|
+
|
145
|
+
##### iOS 8 Location Requirements
|
146
|
+
|
147
|
+
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):
|
148
|
+
|
149
|
+
```ruby
|
150
|
+
app.info_plist['NSLocationAlwaysUsageDescription'] = 'Description'
|
151
|
+
app.info_plist['NSLocationWhenInUseUsageDescription'] = 'Description'
|
152
|
+
```
|
153
|
+
|
154
|
+
*Note: you need both keys to use `get_once`, so it's probably best to just include both no matter what.* See [Apple's documentation](https://developer.apple.com/library/ios/documentation/General/Reference/InfoPlistKeyReference/Articles/CocoaKeys.html#//apple_ref/doc/uid/TP40009251-SW18) on iOS 8 location services requirements for more information.
|
135
155
|
|
136
156
|
#### hide_user_location
|
137
157
|
|
@@ -216,6 +236,75 @@ end
|
|
216
236
|
|
217
237
|
`radius` is the zoom level of the map in miles (default: 10).
|
218
238
|
|
239
|
+
#### tap_to_add(length: Float, target: Object, action: Selector, annotation: Hash)
|
240
|
+
|
241
|
+
Lets a user long press the map to drop an annotation where they pressed.
|
242
|
+
|
243
|
+
##### Default values:
|
244
|
+
|
245
|
+
You can override any of these values. The `annotation` parameter can take any options specified in the annotation documentation above except `:latitude`, `:longitude`, and `:coordinate`.
|
246
|
+
|
247
|
+
```ruby
|
248
|
+
length: 2.0,
|
249
|
+
target: self,
|
250
|
+
action: "gesture_drop_pin:",
|
251
|
+
annotation: {
|
252
|
+
title: "Dropped Pin",
|
253
|
+
animates_drop: true
|
254
|
+
}
|
255
|
+
```
|
256
|
+
|
257
|
+
##### Notifications
|
258
|
+
|
259
|
+
This feature posts two different `NSNotificationCenter` notifications:
|
260
|
+
|
261
|
+
**ProMotionMapWillAddPin:** Fired the moment the long press gesture is recognized, before the pin is added.
|
262
|
+
|
263
|
+
**ProMotionMapAddedPin:** Fired after the pin has been added to the map.
|
264
|
+
|
265
|
+
##### Example:
|
266
|
+
|
267
|
+
```ruby
|
268
|
+
# Simple Example
|
269
|
+
class MyMapScreen < PM::MapScreen
|
270
|
+
title "My Map Screen"
|
271
|
+
tap_to_add length: 1.5
|
272
|
+
def annotations
|
273
|
+
[]
|
274
|
+
end
|
275
|
+
end
|
276
|
+
```
|
277
|
+
|
278
|
+
```ruby
|
279
|
+
# A More Complex Example
|
280
|
+
class MyMapScreen < PM::MapScreen
|
281
|
+
title "My Map Screen"
|
282
|
+
tap_to_add length: 1.5, annotation: {animates_drop: true, title: "A Cool New Pin"}
|
283
|
+
def annotations
|
284
|
+
[]
|
285
|
+
end
|
286
|
+
|
287
|
+
def will_appear
|
288
|
+
NSNotificationCenter.defaultCenter.addObserver(self, selector:"pin_adding:") , name:"ProMotionMapWillAddPin", object:nil)
|
289
|
+
NSNotificationCenter.defaultCenter.addObserver(self, selector:"pin_added:") , name:"ProMotionMapAddedPin", object:nil)
|
290
|
+
end
|
291
|
+
|
292
|
+
def will_disappear
|
293
|
+
NSNotificationCenter.defaultCenter.removeObserver(self)
|
294
|
+
end
|
295
|
+
|
296
|
+
def pin_adding(notification)
|
297
|
+
# We only want one pin on the map at a time
|
298
|
+
clear_annotations
|
299
|
+
end
|
300
|
+
|
301
|
+
def pin_added(notification)
|
302
|
+
# Once the pin is dropped we want to select it
|
303
|
+
select_annotation_at(0)
|
304
|
+
end
|
305
|
+
end
|
306
|
+
```
|
307
|
+
|
219
308
|
---
|
220
309
|
|
221
310
|
### CocoaTouch Property Convenience Methods
|
@@ -7,11 +7,16 @@ module ProMotion
|
|
7
7
|
@params = params
|
8
8
|
set_defaults
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
if @params[:coordinate]
|
11
|
+
@params[:latitude] = @params[:coordinate].latitude
|
12
|
+
@params[:longitude] = @params[:coordinate].longitude
|
13
|
+
@coordinate = @params[:coordinate]
|
14
|
+
elsif @params[:latitude] && @params[:longitude]
|
15
|
+
@coordinate = CLLocationCoordinate2D.new(@params[:latitude], @params[:longitude])
|
16
|
+
else
|
17
|
+
PM.logger.error("You are required to specify :latitude and :longitude or :coordinate for annotations.")
|
18
|
+
nil
|
13
19
|
end
|
14
|
-
@coordinate = CLLocationCoordinate2D.new(@params[:latitude], @params[:longitude])
|
15
20
|
end
|
16
21
|
|
17
22
|
def set_defaults
|
@@ -9,6 +9,7 @@ module ProMotion
|
|
9
9
|
check_annotation_data
|
10
10
|
@promotion_annotation_data = []
|
11
11
|
set_up_start_position
|
12
|
+
set_up_tap_to_add
|
12
13
|
end
|
13
14
|
|
14
15
|
def view_will_appear(animated)
|
@@ -160,9 +161,11 @@ module ProMotion
|
|
160
161
|
end
|
161
162
|
|
162
163
|
def set_start_position(params={})
|
163
|
-
params
|
164
|
-
|
165
|
-
|
164
|
+
params = {
|
165
|
+
latitude: 37.331789,
|
166
|
+
longitude: -122.029620,
|
167
|
+
radius: 10
|
168
|
+
}.merge(params)
|
166
169
|
|
167
170
|
meters_per_mile = 1609.344
|
168
171
|
|
@@ -177,6 +180,42 @@ module ProMotion
|
|
177
180
|
end
|
178
181
|
end
|
179
182
|
|
183
|
+
def set_tap_to_add(params={})
|
184
|
+
params = {
|
185
|
+
length: 2.0,
|
186
|
+
target: self,
|
187
|
+
action: "gesture_drop_pin:",
|
188
|
+
annotation: {
|
189
|
+
title: "Dropped Pin",
|
190
|
+
animates_drop: true
|
191
|
+
}
|
192
|
+
}.merge(params)
|
193
|
+
@tap_to_add_annotation_params = params[:annotation]
|
194
|
+
|
195
|
+
lpgr = UILongPressGestureRecognizer.alloc.initWithTarget(params[:target], action:params[:action])
|
196
|
+
lpgr.minimumPressDuration = params[:length]
|
197
|
+
self.view.addGestureRecognizer(lpgr)
|
198
|
+
end
|
199
|
+
|
200
|
+
def gesture_drop_pin(gesture_recognizer)
|
201
|
+
if gesture_recognizer.state == UIGestureRecognizerStateBegan
|
202
|
+
NSNotificationCenter.defaultCenter.postNotificationName("ProMotionMapWillAddPin", object:nil)
|
203
|
+
touch_point = gesture_recognizer.locationInView(self.view)
|
204
|
+
touch_map_coordinate = self.view.convertPoint(touch_point, toCoordinateFromView:self.view)
|
205
|
+
|
206
|
+
add_annotation({
|
207
|
+
coordinate: touch_map_coordinate
|
208
|
+
}.merge(@tap_to_add_annotation_params))
|
209
|
+
NSNotificationCenter.defaultCenter.postNotificationName("ProMotionMapAddedPin", object:@promotion_annotation_data.last)
|
210
|
+
end
|
211
|
+
end
|
212
|
+
|
213
|
+
def set_up_tap_to_add
|
214
|
+
if self.class.respond_to?(:get_tap_to_add) && self.class.get_tap_to_add
|
215
|
+
self.set_tap_to_add self.class.get_tap_to_add_params
|
216
|
+
end
|
217
|
+
end
|
218
|
+
|
180
219
|
# TODO: Why is this so complex?
|
181
220
|
def zoom_to_fit_annotations(args={})
|
182
221
|
# Preserve backwards compatibility
|
@@ -242,6 +281,18 @@ module ProMotion
|
|
242
281
|
return geocoder.geocodeAddressString(args[:address].to_s, inRegion:args[:region].to_s, completionHandler: callback) if args[:region]
|
243
282
|
end
|
244
283
|
|
284
|
+
def look_up_location(location, &callback)
|
285
|
+
location = CLLocation.alloc.initWithLatitude(location.latitude, longitude:location.longitude) if location.is_a?(CLLocationCoordinate2D)
|
286
|
+
|
287
|
+
if location.kind_of?(CLLocation)
|
288
|
+
geocoder = CLGeocoder.new
|
289
|
+
geocoder.reverseGeocodeLocation(location, completionHandler: callback)
|
290
|
+
else
|
291
|
+
PM.logger.info("You're trying to reverse geocode something that isn't a CLLocation")
|
292
|
+
callback.call nil, nil
|
293
|
+
end
|
294
|
+
end
|
295
|
+
|
245
296
|
########## Cocoa touch methods #################
|
246
297
|
def mapView(map_view, viewForAnnotation:annotation)
|
247
298
|
annotation_view(map_view, annotation)
|
@@ -276,6 +327,7 @@ module ProMotion
|
|
276
327
|
end
|
277
328
|
|
278
329
|
module MapClassMethods
|
330
|
+
# Start Position
|
279
331
|
def start_position(params={})
|
280
332
|
@start_position_params = params
|
281
333
|
@start_position = true
|
@@ -288,6 +340,22 @@ module ProMotion
|
|
288
340
|
def get_start_position
|
289
341
|
@start_position ||= false
|
290
342
|
end
|
343
|
+
|
344
|
+
# Tap to drop pin
|
345
|
+
def tap_to_add(params={})
|
346
|
+
@tap_to_add_params = params
|
347
|
+
@tap_to_add = true
|
348
|
+
end
|
349
|
+
|
350
|
+
def get_tap_to_add_params
|
351
|
+
@tap_to_add_params ||= nil
|
352
|
+
end
|
353
|
+
|
354
|
+
def get_tap_to_add
|
355
|
+
@tap_to_add ||= false
|
356
|
+
end
|
357
|
+
|
358
|
+
|
291
359
|
end
|
292
360
|
def self.included(base)
|
293
361
|
base.extend(MapClassMethods)
|
@@ -301,6 +369,5 @@ module ProMotion
|
|
301
369
|
@location_manager
|
302
370
|
end
|
303
371
|
|
304
|
-
|
305
372
|
end
|
306
373
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ProMotion-map
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mark Rickert
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2015-03-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: ProMotion
|