gpt4 book ai didi

java - 无法解析方法ComputeDistanceBetween

转载 作者:行者123 更新时间:2023-12-01 09:35:19 26 4
gpt4 key购买 nike

我正在使用 Google map 并支持 map fragment 类。我希望程序计算两点之间的距离。但是,我收到一条错误消息,指出我无法解析方法 ComputeDistanceBetween。我该如何解决? (大部分代码取自Github)。

public class DistanceDemoActivity extends BaseDemoActivity implements GoogleMap.OnMarkerDragListener {
private TextView mTextView;
private Marker mMarkerA;
private Marker mMarkerB;
private Polyline mPolyline;
private Object SphericalUtil;


protected int getLayoutId() {
return R.layout.distance_demo;
}


protected void startDemo() {
mTextView = (TextView) findViewById(R.id.textView);

getMap().moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(-33.8256, 151.2395), 10));
getMap().setOnMarkerDragListener(this);

mMarkerA = getMap().addMarker(new MarkerOptions().position(new LatLng(-33.9046, 151.155)).draggable(true));
mMarkerB = getMap().addMarker(new MarkerOptions().position(new LatLng(-33.8291, 151.248)).draggable(true));
mPolyline = getMap().addPolyline(new PolylineOptions().geodesic(true));

Toast.makeText(this, "Drag the markers!", Toast.LENGTH_LONG).show();
showDistance();
}

private void showDistance() {
double distance = SphericalUtil.computeDistanceBetween(mMarkerA.getPosition(), mMarkerB.getPosition());
mTextView.setText("The markers are " + formatNumber(distance) + " apart.");
}

private void updatePolyline() {
mPolyline.setPoints(Arrays.asList(mMarkerA.getPosition(), mMarkerB.getPosition()));
}

private String formatNumber(double distance) {
String unit = "m";
if (distance < 1) {
distance *= 1000;
unit = "mm";
} else if (distance > 1000) {
distance /= 1000;
unit = "km";
}

return String.format("%4.3f%s", distance, unit);
}

@Override
public void onMarkerDragEnd(Marker marker) {
showDistance();
updatePolyline();
}

@Override
public void onMarkerDragStart(Marker marker) {

}

@Override
public void onMarkerDrag(Marker marker) {
showDistance();
updatePolyline();
}
}

最佳答案

SphericalUtil 是 Google Maps API 实用程序库中的一个类,您正在声明一个名为 SphericalUtil 的对象

删除此行:

private Object SphericalUtil;

此外,请确保您将 Google Maps API 实用程序库添加到 instructions 之后的 build.gradle 中。 .

关于java - 无法解析方法ComputeDistanceBetween,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39027352/

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