좌표 쌍을 역 지오 코딩하여 사용자의 도시를 찾고 있지만 도시를 Motion-Kit 레이아웃으로 옮기는 데 어려움이 있습니다. 도시를 배치하기에 가장 좋은 방법은 무엇입니까? API의 다른 정보도 레이아웃에 추가하므로 동일한 문제가 발생할 수 있습니다.Motion-Kit 레이아웃에서 비동기 적으로 획득 된 데이터 사용
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
내가 HomeScreen
이 방법에서 @city
얻을 :
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
내가 그렇게처럼 AppDelegate에에 on_activate
에서에서 App::Persistence['latitude']
를 얻을 :
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
어떤 도움도 감사하겠습니다. ated. 미리 감사드립니다.