ユーザーの都市を見つけるために座標のペアを逆ジオコーディングしていますが、都市を Motion-Kit レイアウトに入れるのに苦労しています。都市をレイアウトに組み込む最良の方法は何ですか? また、API からレイアウトに他の情報を追加する予定なので、同じ問題が発生する可能性があります。
次のような基本的な MK レイアウトがあります。
class HomeLayout < MK::Layout
def initialize(data)
@city = data[:city]
super
end
def layout
add UILabel, :location
end
def location_style
text @city
color :white.uicolor
font UIFont.fontWithName("Avenir", size: 22)
size_to_fit
center ['50%', 80]
end
end
私@city
はこのメソッドから取得しHomeScreen
ます:
def city
loc = CLLocation.alloc.initWithLatitude App::Persistence['latitude'], longitude: App::Persistence['longitude']
geo = CLGeocoder.new
geo.reverseGeocodeLocation loc, completionHandler: lambda { |result, x|
return result[0].locality
}
# This currently returns a CLGeocoder object, but I want it to return the city as a String.
end
次のように、AppDelegateApp::Persistence['latitude']
から取得します。on_activate
def on_activate
BW::Location.get_once do |result|
if result.is_a?(CLLocation)
App::Persistence['latitude'] = result.coordinate.latitude
App::Persistence['longitude'] = result.coordinate.longitude
open HomeScreen.new
else
LocationError.handle(result[:error])
end
end
end
どんな助けでも大歓迎です。ありがとうございます。