gpt4 book ai didi

java - 以 GPS 格式计算数学

转载 作者:行者123 更新时间:2023-12-01 14:22:44 24 4
gpt4 key购买 nike

我正在制作一个 Android 应用程序来计算 GPS 格式的数学。

示例:

给定

北纬 48°44.(30x4) 东经 019°08.[(13x31)+16]

App进行计算,结果为:

北纬 48°44.120 东经 019°08.419

可以这样做吗?

我搜索了插件和解决方案,但这些都只是针对数学字符串,例如“14 + 6”。

最佳答案

我假设您正在使用 Java 工作,因为它在您的问题中被标记。

您可以为 GPS 坐标创建一个新的公共(public)类,并将坐标的实际值存储在最低分度中,根据您的示例,该值似乎是分钟或秒。这允许您将值存储为 int 或 double 并具有您希望的任何精度。然后,您可以创建一组私有(private)和公共(public)方法来完成您的数学运算,并创建其他方法以适当的方式显示您的值:

public class GPSCoordinate {

private double verticalcoord;
private double horizontalcoord;

//Constructors
GPSCoordinate(){
setVertical(0);
setHorizontal(0);
}

GPSCoordinate(double vert, double horiz){
setVertical(vert);
setHorizontal(horiz);
}

//Display methods
public String verticalString(){
return ((int)verticalcoord / 60) + "°" + (verticalcoord - ((int)verticalcoord / 60) *60);
}

public String horizontalString(){
return ((int)horizontalcoord / 60) + "°" + (horizontalcoord - ((int)horizontalcoord / 60) *60);
}

//Setting Methods
public void setVertical(double x){
this.verticalcoord = x;
}

public void setHorizontal(double x){
this.horizontalcoord = x;
}

//Math Methods
public void addMinutesVertical(double x){
this.verticalcoord += x;
}
}

这将允许您使用给定的 GPS 坐标在主代码中启动一个实例,然后您可以在其上调用数学函数。

GPSCoordinate coord1 = new GPSCoordinate(567.23, 245);
coord1.addMinutesVertical(50);
coord1.otherMathFunction(50 * 30);

当然,您需要完善上述内容以使其适合您的项目。如果这没有帮助,请提供更多细节,我会看看是否能想到其他可能符合您需求的内容。

关于java - 以 GPS 格式计算数学,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17407557/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com