我试图调用坐标,当一个按钮被按下,并使我的地图到那些坐标。 但是,每次我尝试将它更改为双精度或字符串时,都会得到一个新的错误。 代码:
private void updateLocationUI() {
if (mCurrentLocation != null) {
mLatitudeTextView.setText(String.format(Locale.ENGLISH, "%s: %f", mLatitudeLabel,
mCurrentLocation.getLatitude()));
mLongitudeTextView.setText(String.format(Locale.ENGLISH, "%s: %f", mLongitudeLabel,
mCurrentLocation.getLongitude()));
mLastUpdateTimeTextView.setText("Date/Time:"+ " " + currentDateandTime);
LatLng maryland = new LatLng(mLatitudeTextView, mLongitudeTextView);
mMap.moveCamera(CameraUpdateFactory.newLatLng(maryland));
mMap.setMinZoomPreference(8.0f);
}
}
不起作用的部分是mLatitudeTextView和mLitementudeTextView。 有什么想法吗?
这样做
private void updateLocationUI() {
if (mCurrentLocation != null) {
mLatitudeTextView.setText(String.format(Locale.ENGLISH, "%s: %f", mLatitudeLabel,
mCurrentLocation.getLatitude()));
mLongitudeTextView.setText(String.format(Locale.ENGLISH, "%s: %f", mLongitudeLabel,
mCurrentLocation.getLongitude()));
mLastUpdateTimeTextView.setText("Date/Time:"+ " " + currentDateandTime);
LatLng maryland = new LatLng(mCurrentLocation.getLatitude(), mCurrentLocation.getLongitude());
mMap.moveCamera(CameraUpdateFactory.newLatLng(maryland));
mMap.setMinZoomPreference(8.0f);
}
}
我假设getLatitude()
和getLongitude(
)返回双倍
更改此内容:
LatLng maryland = new LatLng(mLatitudeTextView, mLongitudeTextView)
To:LatLng maryland=new LatLng(MLatitudeTextView.getText(),MlongitudeTextView.getText())
您必须从文本组件中提取实际文本,并将其转换为数字。 一种方法是使用double.parseDouble
方法。
double lat = Double.parseDouble(mLatitudeTextView.getText().toString());
double lng = Double.parseDouble(mLongitudeTextView.getText().toString());
LatLng maryland = new LatLng(lat, lng);