0
我已经在消除错误尝试了很多,但无法删除一个错误是不兼容的类型地址不兼容的类型地址的Android
public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {
EditText ed;
Button btn;
private GoogleMap mMap;
List<Address> addressList;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
ed=(EditText)findViewById(R.id.ed);
btn=(Button)findViewById(R.id.btn);
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}
public void onsearch()
{
String location=ed.getText().toString();
if(location!=null|| !location.equals("")){
Geocoder geocoder=new Geocoder(this);
try {
addressList=geocoder.getFromLocationName(location,1);
} catch (IOException e) {
e.printStackTrace();
}
Address address=addressList.get(0);
LatLng latLng=new LatLng(address.getLatitude(),address.getLongitude());
mMap.addMarker(new MarkerOptions().position(latLng).title("marker"));
mMap.animateCamera(CameraUpdateFactory.newLatLng(latLng));
}
}
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
return;
}
mMap.setMyLocationEnabled(true);
LatLng sydney = new LatLng(-34, 151);
mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
}
}
请帮助在错误对话框中显示 。对话框显示找到android.location.address需要列表导入com.google.android.gms.identity.intents.Address
在导入com.google.android.gms.identity.intents.Address存在,但它仍然创建不兼容的错误,但我仍然使用地址列表语句 –
是的,我不相信你想要的导入。 Geocoder返回android.location.Address,您需要导入或显式声明您的地址变量。 – Ben
是啊,我已经使用地理编码器仍然进口未在AddressList中陈述发生的事情,你可以给这个的替代,如果是请出示 –