使用 Map Kit 如何找到我的位置?

发布于 2024-11-15 05:28:37 字数 157 浏览 0 评论 0原文

我需要在 Map Kit 中显示我当前的位置,我该怎么做?

self.map.showsUserLocation = TRUE;

没有显示我的位置,而是显示地图上其他位置的点?我需要找到访问应用程序的位置。 请帮助我。 提前致谢

I need to display my current position in Map Kit, how can I do this ?

self.map.showsUserLocation = TRUE;

is not showing my location instead a point somewhere else in the map? I need to find the location from where I am accessing the application.
Please help me in this..
Thanks in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

为人所爱 2024-11-22 05:28:37

您需要使用位置管理器来获取您当前的位置。然后获取经纬度值并创建注释并显示在地图上。如果使用map.showsUserLocation = TRUE;它将显示您在实际设备中的当前位置。

注意 - 在模拟器地图套件中显示苹果总部位于库比蒂诺某处 - 我不太记得了。

You need to use location manager for getting your current location. And then get the lat long value and create a annonation and display on map. If you use map.showsUserLocation = TRUE; it will show your current location in actual device.

Note - In simulator map kit shows apple's head quarter location somewhere in Cupertino - I don't remember exactly.

野稚 2024-11-22 05:28:37
-(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation{



int degrees = newLocation.coordinate.latitude;
double decimal = fabs(newLocation.coordinate.latitude - degrees);
int minutes = decimal * 60;
double seconds = decimal * 3600 - minutes * 60;
NSString *lat = [NSString stringWithFormat:@"%d° %d' %1.4f\"",degrees, minutes, seconds];                   
latLabel.text = lat;
degrees = newLocation.coordinate.longitude;
decimal = fabs(newLocation.coordinate.longitude - degrees);
minutes = decimal * 60;
seconds = decimal * 3600 - minutes * 60;
NSString *longt = [NSString stringWithFormat:@"%d° %d' %1.4f\"",
                   degrees, minutes, seconds];
longLabel.text = longt;
MKCoordinateRegion region = { {0.0, 0.0 }, { 0.0, 0.0 } }; 
region.center.latitude = newLocation.coordinate.latitude;
region.center.longitude = newLocation.coordinate.longitude;
region.span.longitudeDelta = 0.01f;
region.span.latitudeDelta = 0.01f;
[mapView setRegion:region animated:YES]; 
[mapView setDelegate:self];
}
-(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation{



int degrees = newLocation.coordinate.latitude;
double decimal = fabs(newLocation.coordinate.latitude - degrees);
int minutes = decimal * 60;
double seconds = decimal * 3600 - minutes * 60;
NSString *lat = [NSString stringWithFormat:@"%d° %d' %1.4f\"",degrees, minutes, seconds];                   
latLabel.text = lat;
degrees = newLocation.coordinate.longitude;
decimal = fabs(newLocation.coordinate.longitude - degrees);
minutes = decimal * 60;
seconds = decimal * 3600 - minutes * 60;
NSString *longt = [NSString stringWithFormat:@"%d° %d' %1.4f\"",
                   degrees, minutes, seconds];
longLabel.text = longt;
MKCoordinateRegion region = { {0.0, 0.0 }, { 0.0, 0.0 } }; 
region.center.latitude = newLocation.coordinate.latitude;
region.center.longitude = newLocation.coordinate.longitude;
region.span.longitudeDelta = 0.01f;
region.span.latitudeDelta = 0.01f;
[mapView setRegion:region animated:YES]; 
[mapView setDelegate:self];
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文