【发布时间】:2014-12-03 18:09:43
【问题描述】:
我正在对一对坐标进行反向地理编码以找到用户所在的城市,但很难将城市置于 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
我从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
任何帮助将不胜感激。提前谢谢。
【问题讨论】:
标签: ios rubymotion rubymotion-promotion