注意:这是我的好奇心练习,已有解决此问题的功能/代码(另请参见注释)
可以在此处找到用于计算日出和日落时间的算法,以及在1 in Tcl和2 in的实现javascript。
我正在尝试将算法转换为PHP,但是这有点麻烦,并且花费太多时间。到目前为止,这是我的结果:
<?php
$sunrise = sunriseSunsetTimeTest(9, 4, 2015, 46.929512, 7.565272);
$sunset = sunriseSunsetTimeTest(9, 4, 20, 46.929512, 7.565272, 'sunset');
echo $sunrise . '/' . $sunset;
/* output is: 12.314714533758/12.612340511889 (?) */
function sunriseSunsetTimeTest($day, $month, $year, $latitude, $longitude,
$which='sunrise', $localTimeOffset=1, $zenith=96){
/*
* Output:
* sunrise or sunset time depending on parameter $which
*
* Input:
* (int) day
* (int) month
* (int) year
* (float) latitude_degree
* (float) longitude_degree …Run Code Online (Sandbox Code Playgroud) 我的新"正在进行的应用程序"使用CLLocationManager的实例用于多种目的.为了使应用程序尽可能对电池友好,应仅在需要时激活位置服务,并在数据刷新完成后立即停用.出于我的目的,仅在10秒内获取一次位置数据就足够了.(尚未确定确切的间隔长度).
我的问题是,"关闭位置服务"的电池效率最高的方法是什么?仅使用"stopUpdatingLocation"方法并将CLLocationManager本身保留在内存中是否足够,或者我是否需要释放整个实例,并在下次刷新之前分配一个新实例?