扮演替身?

发布于 2024-10-21 08:57:14 字数 680 浏览 6 评论 0原文

我怎样才能将某些东西变成双倍? CLLocationDegrees 实际上是一个双精度数,那么我如何将其转换为双精度数,以便我的 if 始终返回双精度数,并且我可以将 findAllLocalCountTotal 参数更改为双精度数而不是 CLLocationDegrees?

if(self.lastKnownLocation == nil ){
    double lat = [CLController sharedInstance].latitude;
    double lng = [CLController sharedInstance].longitude;

}else{
    CLLocationDegrees lat = self.lastKnownLocation.coordinate.latitude;
    CLLocationDegrees lng = self.lastKnownLocation.coordinate.longitude;
}

NSNumber *tempInt = self.lastPostsGrabbedCounter;



//Make call to get data with lat lng
self.webServiceAllCount = [Post findAllLocalCountTotal:(CLLocationDegrees)lat withLong:(CLLocationDegrees)lng];

How can I turn or maybe cast something to a double? CLLocationDegrees is really a double so how do I cast it as double so my if always returns doubles and I can change my findAllLocalCountTotal params to double instead of CLLocationDegrees?

if(self.lastKnownLocation == nil ){
    double lat = [CLController sharedInstance].latitude;
    double lng = [CLController sharedInstance].longitude;

}else{
    CLLocationDegrees lat = self.lastKnownLocation.coordinate.latitude;
    CLLocationDegrees lng = self.lastKnownLocation.coordinate.longitude;
}

NSNumber *tempInt = self.lastPostsGrabbedCounter;



//Make call to get data with lat lng
self.webServiceAllCount = [Post findAllLocalCountTotal:(CLLocationDegrees)lat withLong:(CLLocationDegrees)lng];

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

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

发布评论

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

评论(2

自由范儿 2024-10-28 08:57:14

只需使用强制转换并将变量声明移到 if 之外 - if & else 分支是不同的作用域,并引入了自己的变量:

double lat, lng;
if(self.lastKnownLocation == nil)
{
   lat = [CLController sharedInstance].latitude;
   lng = [CLController sharedInstance].longitude;
}
else
{
   lat = (double)self.lastKnownLocation.coordinate.latitude;
   lng = (double)self.lastKnownLocation.coordinate.longitude;
}

Just use a cast and also move the variable declaration outside of the if - the if & else branches are distinct scopes and introduced their own variables:

double lat, lng;
if(self.lastKnownLocation == nil)
{
   lat = [CLController sharedInstance].latitude;
   lng = [CLController sharedInstance].longitude;
}
else
{
   lat = (double)self.lastKnownLocation.coordinate.latitude;
   lng = (double)self.lastKnownLocation.coordinate.longitude;
}
别想她 2024-10-28 08:57:14

这个话题可以帮助你吗? cllocation Degrees

This topic can help you ? cllocationdegrees

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文