我正在尝试让应用程序输入纬度和经度,并计算到位置之间的距离,并在标记位置之间绘制折线,但折线未完全绘制到其他目的地。这是我的代码`
strtod
//这里我将Polyline添加到Onclick
public class MainActivity extends AppCompatActivity implements OnMapReadyCallback {
private TextView source;
private TextView destination;
private EditText sLatitude1;
private EditText sLongtiude1;
private EditText dLatitude2;
private EditText dLongtiude2;
private Button button;
private GoogleMap mMap;
boolean mapReady = false;
MarkerOptions place1;
MarkerOptions place2;
Location location;
double lati1;
double longi1;
double lati2;
double longi2;
TextView textView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// find text that display distance
textView = (TextView) findViewById(R.id.distance);
MapFragment mapFragment = (MapFragment) getFragmentManager().findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
// find edit text and text view
source = (TextView) findViewById(R.id.sourc);
destination = (TextView) findViewById(R.id.destination);
sLatitude1 = (EditText) findViewById(R.id.lat1);
sLongtiude1 = (EditText) findViewById(R.id.long1);
dLatitude2 = (EditText) findViewById(R.id.lat2);
dLongtiude2 = (EditText) findViewById(R.id.long2);
// find button
button = (Button) findViewById(R.id.getDistance);
//我不知道为什么不完成
答案 0 :(得分:1)
你以错误的方式添加了折线!
mMap.addPolyline(new PolylineOptions().geodesic(true)
.add(new LatLng(lati1, longi1))
.add(new LatLng(lati2, lati2)));
在lat2,lat2中添加了一个点!
mMap.addPolyline(new PolylineOptions().geodesic(true)
.add(new LatLng(lati1, longi1))
.add(new LatLng(lati2, longi2)));