GoogleMap move map camera to particular location

1

I added the map in the fragment, it is already appearing, until I added a random marker with the map initializing it. the problem is that now I'm using GeoCoder.

I put the address in edittext and it converts to Lng and Lat, so that's fine, it's converting and saving in the database.

What I want now is that by entering the name London (for example) and pressing the FIND button, it changes the map camera to the lat and lng of london.

The error you are giving is java.lang.NullPointerException .

MapsActivity mapa = new MapsActivity();
    getSupportFragmentManager().beginTransaction().replace(R.id.fragLayout, mapa).commit();

GeoCoder

String stringLocal = localizacao.getText().toString();
    //Convertendo endereço para coordenada

    Geocoder geocoder = new Geocoder(this, Locale.getDefault());
    List<Address> addresses = null;
    try {
        addresses = geocoder.getFromLocationName(stringLocal, 1);
    } catch (IOException e) {
        e.printStackTrace();
    }
    Address address = addresses.get(0);
    double longitude = address.getLongitude();
    double latitude = address.getLatitude();

Find button code.

 if (view == ACHAR) {
        LatLng latLng = new LatLng(latitude, longitude);
        map.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng, 20));
        map.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null);
    }

MapsFragment

public class MapsFragment extends BaseFragment implements OnMapReadyCallback {
private GoogleMap mMap;
@Override
public View onCreateView(LayoutInflater inflate, ViewGroup container, Bundle savedInstanceState) {
    super .onCreate(savedInstanceState);
    View view = inflate.inflate(R.layout.activity_maps, container, false);
    // Obtain the SupportMapFragment and get notified when the map is ready to be used.
    SupportMapFragment mapFragment = (SupportMapFragment) getChildFragmentManager().findFragmentById(R.id.map);
    mapFragment.getMapAsync(this);
    return view;
}
@Override
public void onMapReady(GoogleMap googleMap) {
    mMap = googleMap;

    // Add a marker in Sydney and move the camera
    LatLng sydney = new LatLng(-34, 151);
    mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
    mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
}

}

    
asked by anonymous 31.10.2015 / 22:49

0 answers