在我的 Android 应用程序上的谷歌地图中添加“我的位置”按钮

Gra*_*lum 3 eclipse android google-maps

我正在尝试在我的 Android 应用程序中添加我的位置按钮。这是我目前拥有的代码:

public class MapActivity extends FragmentActivity {


    private GoogleMap googleMap;
    int position;
    String alllatitude,alllongitude,alldirname;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.map_activity);

        Intent i=getIntent();

        position=i.getIntExtra("POSITION", 0);

        alllatitude=i.getStringExtra("LATITUDE");
        alllongitude=i.getStringExtra("LONGITUDE");
        alldirname=i.getStringExtra("DIRNAME");
        LatLng TutorialsPoint = new LatLng(Double.parseDouble(alllatitude), Double.parseDouble(alllongitude));
        try {
            if (googleMap == null) {
                googleMap = ((MapFragment) getFragmentManager()
                        .findFragmentById(R.id.map)).getMap();
            }
            googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
            googleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(TutorialsPoint, 15.0f));
            googleMap.addMarker(new MarkerOptions().position(TutorialsPoint)
                    .title(alldirname));
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

}
Run Code Online (Sandbox Code Playgroud)

任何帮助将非常感激。

Zee*_*med 8

使用此按钮可在 Android 版 Google Maps V2 API 上显示默认位置按钮。

googleMap.setMyLocationEnabled(true); 

googleMap.getUiSettings().setMyLocationButtonEnabled(true);
Run Code Online (Sandbox Code Playgroud)