如何获取iPhone地图中当前位置的坐标值?
我是 iPhone 开发新手。我正在创建一个地图应用程序。我正在获取当前位置并能够以 %g 格式打印坐标。该格式是什么。我可以将坐标保存在整数局部变量中以进行加载吗地图中的当前位置。请帮助我。是否有其他替代方法可以通过获取其值来加载设备中的当前位置。
NSLog(@"%g", newLocation.coordinate.latitude);
NSLog(@"%g", newLocation.coordinate.longitude);
这会打印该值。但是我如何将该值保存为整数?请帮助我。谢谢。
编辑
double val1=newLocation.coordinate.latitude;
double val2=newLocation.coordinate.longitude;
MKCoordinateRegion region1;
region1.center.latitude=val1;
region1.center.longitude=val2;
region1.span.latitudeDelta=0.0;
region1.span.longitudeDelta=0.0;
mapView.mapType=MKMapTypeHybrid;
mapView.region=region1;
控制台窗口
2010-02-18 23:29:29.403 eDev[5817:207] val 1 is 37.331689
2010-02-18 23:29:29.403 eDev[5817:207] val 2 is -122.031
2010-02-18 23:29:29.404 eDev[5817:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Invalid Region <center:+37.33168900, -122.03073100 span:+0.00000000, +0.00000000>'
2010-02-18 23:29:29.404 eDev[5817:207] Stack: (
31417435,
2477657929,
31576513,
I am new to iphone development.I am creating a map application.I am getting the current location and able to print the co-ordinates with %g format.What is that format.Can i save the coordinates in a integer local variable to load the current location in map. please help me out.Is there any other alternate to load the current location in device by getting its value.
NSLog(@"%g", newLocation.coordinate.latitude);
NSLog(@"%g", newLocation.coordinate.longitude);
This prints the value .but how can i save this value in integer?Please help me out.Thanks.
EDIT
double val1=newLocation.coordinate.latitude;
double val2=newLocation.coordinate.longitude;
MKCoordinateRegion region1;
region1.center.latitude=val1;
region1.center.longitude=val2;
region1.span.latitudeDelta=0.0;
region1.span.longitudeDelta=0.0;
mapView.mapType=MKMapTypeHybrid;
mapView.region=region1;
The console window
2010-02-18 23:29:29.403 eDev[5817:207] val 1 is 37.331689
2010-02-18 23:29:29.403 eDev[5817:207] val 2 is -122.031
2010-02-18 23:29:29.404 eDev[5817:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Invalid Region <center:+37.33168900, -122.03073100 span:+0.00000000, +0.00000000>'
2010-02-18 23:29:29.404 eDev[5817:207] Stack: (
31417435,
2477657929,
31576513,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
跨度纬度/经度增量不能为零。尝试类似 0.01 的值。
The span lat/long delta cannot be zero. Try something like 0.01.