android中不兼容的类型地址

时间:2016-07-21 14:25:57

标签: java 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));
}

}

请在错误对话框中显示帮助 .dialog框显示发现android.location.address需要List import com.google.android.gms.identity.intents.Address

1 个答案:

答案 0 :(得分:0)

听起来你的导入声明错了。如果您提供错误堆栈跟踪和完整的源代码(包括导入),将会很有帮助。