java - 打印出地理位置对象的字段时出错
问题描述
import java.util.*;
public class RoadTrip
{
ArrayList<GeoLocation> roadTrip = new ArrayList<GeoLocation>();
double cheat = 0;
// Create a GeoLocation and add it to the road trip
public void addStop(String name, double latitude, double longitude)
{
GeoLocation loc = new GeoLocation(name + " ", latitude, longitude);
roadTrip.add(loc);
}
// Get the total number of stops in the trip
public int getNumberOfStops()
{
return roadTrip.size();
}
// Get the total miles of the trip
public double getTripLength()
{
double totalDistance = 0;
for (int i = 1; i < roadTrip.size(); i++ )
{
GeoLocation here = roadTrip.get(i);
GeoLocation prev = roadTrip.get(i-1);
totalDistance = totalDistance + here.distanceFrom(prev);
}
return totalDistance;
}
// Return a formatted toString of the trip
public String toString()
{
int i = 0;
String retVal="";
for( Object test: roadTrip)
{
retVal = retVal + ( i + 1 ) + ". " + test + "\n";
i++;
}
return retVal;
}
}
当我返回 retVal 时,它返回值
- 粉末弹簧(-110.97168, -110.97168)
- 阿贡(-149.00134, -149.00134)
- 斑马(-84.74096, -84.74096)
- Hyampom(-53.2522, -53.2522)
- 北费尔菲尔德(47.05816, 47.05816)
什么时候应该返回
- 粉末弹簧 (70.47312, -110.97168)
- 阿贡 (-12.26804, -149.00134)
- 斑马 (-3.89922, -84.74096)
- Hyampom (84.57072, -53.2522)
- 北费尔菲尔德 (73.14154, 47.05816)
问题是纬度值由于某种原因等于经度值。
编辑:忘了我在弄乱代码并删除了纬度部分,把它放回去;仍然给出相同的结果
解决方案
发现错误。一个与我一起工作的人更改了地理位置中的一些代码,但没有通知我。
推荐阅读
- reactjs - 在 JWT 身份验证 React Django 中几分钟后,用户名状态变为 undefined / null
- node.js - WebSocket 握手期间出错:意外的响应代码:431
- python - 使用 python scipy.curve_fit() 拟合拉伸指数
- xml - 为什么 DocuSign CustomFields 不从信封反序列化?
- javascript - 如何防止提示继续按键事件?
- javascript - 如何在ANTD的FormItem中设置Mutlti Select的初始值
- sql-server - 将时间求和为持续时间
- three.js - 我不明白 a-frame 中的“实体相机”代码行
- php - 如何限制树视图中显示的图像数量?
- android - React 本机应用程序卡在 Android 上的“飞溅”中