JAVA学习打卡 Day2

Java学习打卡 day2

第二天打卡😝

Java变量初涉

先来康康java中变量是如何读取的

package hello;

import java.util.Scanner;

public class Input {
   

	public static void main(String[] args) {
   
		// TODO 自动生成的方法存根
		Scanner in=new
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要判断打卡范围,需要通过定位功能获取当前位置的经纬度,然后与打卡范围进行比较。可以参考以下步骤: 1. 使用Android中的LocationManager来获取当前位置的经纬度。 2. 定义打卡范围,可以使用一个圆形区域表示,可以由圆心坐标和半径表示。 3. 计算当前位置与圆心之间的距离,如果距离小于等于半径,则说明当前位置在打卡范围内。 4. 根据需要进行相应的处理,如打卡成功或失败等。 以下是一个简单的示例代码: ```java LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); Location currentLocation = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); double latitude = currentLocation.getLatitude(); double longitude = currentLocation.getLongitude(); // 打卡范围圆心坐标 double centerLatitude = 31.225434; double centerLongitude = 121.482536; // 打卡范围半径(单位:米) double radius = 500; // 计算当前位置与圆心之间的距离 double distance = distance(latitude, longitude, centerLatitude, centerLongitude); if (distance <= radius) { // 打卡成功 } else { // 打卡失败 } // 计算两个经纬度之间的距离 private double distance(double lat1, double lng1, double lat2, double lng2) { double earthRadius = 6378137; // 地球半径(单位:米) double radLat1 = Math.toRadians(lat1); double radLat2 = Math.toRadians(lat2); double a = radLat1 - radLat2; double b = Math.toRadians(lng1) - Math.toRadians(lng2); double s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) + Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(b / 2), 2))); s *= earthRadius; return s; } ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值