如何在 xcode 模拟器中获取当前的经度和纬度?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16082254/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to get current longitude and latitude in xcode simulator?
提问by Adnan Khan
I am trying to get current long and lat by location but i am getting both 0.0000, the following code i am using
我正在尝试按位置获取当前的经度和纬度,但我同时得到了 0.0000,我正在使用以下代码
(CLLocationCoordinate2D) getLocation{
CLLocationManager *locationManager = [[[CLLocationManager alloc] init] autorelease];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
locationManager.distanceFilter = kCLDistanceFilterNone;
[locationManager startUpdatingLocation];
CLLocation *location = [locationManager location];
CLLocationCoordinate2D coordinate = [location coordinate];
return coordinate;
}
And to call it use:
并称之为使用:
CLLocationCoordinate2D coordinate = [self getLocation];
NSString *latitude = [NSString stringWithFormat:@"%f", coordinate.latitude];
NSString *longitude = [NSString stringWithFormat:@"%f", coordinate.longitude];
NSLog(@"*dLatitude : %@", latitude);
NSLog(@"*dLongitude : %@",longitude);
i also added corelocation to the project. please advise me.
我还在项目中添加了核心定位。请建议我。
回答by chirag
Implement delegate method of location manager
实现位置管理器的委托方法
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation: (CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
and you can get lat and lng using newLocation.coordinate.latitude
and newLocation.coordinate.longitude
你可以使用newLocation.coordinate.latitude
和得到 lat 和 lngnewLocation.coordinate.longitude
And for set current location in simulator you can follow @ios_av
对于在模拟器中设置当前位置,您可以关注@ios_av
回答by ios_av
IPHone simulator always give 0.0000 for lat and long because it doesn't detect the location.
IPHone 模拟器总是为 lat 和 long 提供 0.0000,因为它没有检测到位置。
You can add Custom Location using this path: Select iPhone Simulator and select Debug -->Loction --> Custom Location
您可以使用此路径添加自定义位置: 选择 iPhone 模拟器并选择调试 --> 位置 --> 自定义位置
回答by Prasad G
You have to add Custom Location using this path:
Select iPhone Simulator and select Debug -->Loction --> Custom Location
in menu
您必须使用此路径添加自定义位置:选择 iPhone 模拟器并Debug -->Loction --> Custom Location
在菜单中选择
回答by Tarun Chaudhary
try this
尝试这个
- Run project in iPhone Simulator
- Create in TextEdit file following file, call it MyOffice for example. Make extension as .gpx
- Select in Xcode at the Simulate area
Add GPX File to Project...
- Add created file from menu to project.
- Now you can see your location in Simulate area:
- 在 iPhone 模拟器中运行项目
- 在 TextEdit 文件中创建以下文件,例如将其命名为 MyOffice。将扩展名设为 .gpx
- 在 Xcode 中的 Simulate 区域中选择
Add GPX File to Project...
- 将创建的文件从菜单添加到项目。
- 现在您可以在模拟区域看到您的位置:
回答by Tarun Chaudhary
simulator can not return current location,its gives default california latitude and longitude location,but you can set statically location in simulator by - Debug -> Location -> Custom Location
模拟器无法返回当前位置,它给出了默认的加利福尼亚纬度和经度位置,但您可以通过 - 调试 -> 位置 -> 自定义位置在模拟器中静态设置位置
回答by meronix
in simulator you can force a local position: go to menu:debug:position and chose one of the voices (some simulates movements via a preregistered route) or enter coordinates of your choice
在模拟器中,您可以强制本地位置:转到菜单:调试:位置并选择其中一种声音(有些通过预先注册的路线模拟运动)或输入您选择的坐标
回答by Navnath Godse
If you want to get you current location in your app then check this tutorial
http://www.techotopia.com/index.php/An_Example_iOS_5_iPhone_Location_Application
If you are not running this on device then add your latitude and longitude for simulator
for that check this
https://stackoverflow.com/a/12637537/2106973
如果您想在您的应用程序中获取当前位置,请查看本教程
http://www.techotopia.com/index.php/An_Example_iOS_5_iPhone_Location_Application
如果您没有在设备上运行此程序,请添加模拟器的纬度和经度以
查看此
https://stackoverflow.com/a/12637537/2106973