在android中设置所需的位置

时间:2017-10-01 23:07:24

标签: java android cross-platform

如何在android中设置所需位置,并在半径范围内为用户提供10个点

final Button hereButton = (Button) findViewById(R.id.getPoints);
hereButton.setOnClickListener(new View.OnClickListener(){
   public void onClick(View v){
String coordinates[] = {"40.000000", "-80.000000"};
    double lat = Double.parseDouble(coordinates[0]);
    double lng = Double.parseDouble(coordinates[1]);
final double radius = 480; //0.3 miles
//distance = coordinates.distance(from: userLocation)
if coordinates < radius
    {
        Total_Points += 10
    }



        }
    });

1 个答案:

答案 0 :(得分:0)

假设您的java代码中有相同的类:

int Total_Points = 0;
CLLocation desiredlocation = CLLocation(45.000000,-80.000000);
Double radius = 480; // ~0.3 miles

Double distance = desiredlocation.distance(userLocation);
if (distance < radius){

   Total_Points += 10;
   pointsLabel.setText("Total Points: \(Total_Points)");

    getPointsOutlet.isEnabled = false;

  }


 save.setValue(Total_Points, "Total Points");

但是如果你想要这个swift代码的android等价物,那么它就是