简体   繁体   中英

Google map v2 marker not starting with my location

        SupportMapFragment fm = (SupportMapFragment) getSupportFragmentManager()
                .findFragmentById(R.id.map);

        googleMap = fm.getMap();

        googleMap.setMyLocationEnabled(true);

        Marker marker = googleMap.addMarker(new MarkerOptions()
                  .position(new LatLng(location.getLatitude(),location.getLongitude()))
                  .title("Me")
                  .snippet("Population: 776733"));

When I run the code,google map is supposed to show the place where I am with the marker,but the map is opening up with some other place,no my current location,and I have to move to my location manually to find the marker.

You should animateCamera on that particular location Marker like

LatLng current_loc= new LatLng(lat, lng);
mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(current_loc, 18.0f));

For more information go to https://developers.google.com/maps/documentation/android/views#moving_the_camera

尝试这个,

googleMap.moveCamera(CameraUpdateFactory.newLatLng(new LatLng(your latitude, you longitude)));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM