您能否查看以下代码,它确实尝试使用委托的locationManager,并尝试返回设备的当前位置。
但总是返回0(允许位置许可)
的.m
<key>NSLocationAlwaysUsageDescription</key>
<string>We would like to use your location.</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>We would like to use your location.</string>
info.plist中
import web
import json
urls = (
'/', 'index'
'/runs', 'runs'
)
app = web.application(urls, globals())
class index:
def GET(self):
render = web.template.render('templates/')
return render.index()
class runs:
def GET(self):
return "Test"
if __name__ == "__main__": app.run()
答案 0 :(得分:0)
请在requestAlwaysAuthorization之后尝试调用startUpdatingLocation。并使用下面的didUpdateLocations委托方法。
if(IS_OS_8_OR_LATER) {
[self.locationManager requestAlwaysAuthorization];
}
[self.locationManager startUpdatingLocation];
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations{
_currentLocation = [locations objectAtIndex:0];
//do your stuff with the location
}
用于模拟器测试 - 选择模拟器并转到调试 - &gt;位置 - &gt; Apple或City Run
对于设备测试如果您正在获取当前位置,请查看地图。有时设备因房屋内部而无法获得当前位置。