相关疑难解决方法(0)

如何在谷歌地图android中获取当前位置

其实我的问题是我没有得到当前的位置纬度和经度我尝试了很多方法.我知道这个问题已经问过我试过那个答案还是我还没有得到答案.请帮助我代码:

    if (googleMap == null) {
        googleMap = ((MapFragment) getFragmentManager().findFragmentById(
                R.id.map)).getMap();

        // check if map is created successfully or not
        if (googleMap == null) {
            Toast.makeText(getApplicationContext(),
                    "Sorry! unable to create maps", Toast.LENGTH_SHORT)
                    .show();
        }
    }
    googleMap.setMyLocationEnabled(true);
    Location myLocation = googleMap.getMyLocation();  //Nullpointer exception.........
    LatLng myLatLng = new LatLng(myLocation.getLatitude(),
            myLocation.getLongitude());

    CameraPosition myPosition = new CameraPosition.Builder()
            .target(myLatLng).zoom(17).bearing(90).tilt(30).build();
    googleMap.animateCamera(
        CameraUpdateFactory.newCameraPosition(myPosition));
Run Code Online (Sandbox Code Playgroud)

android google-maps

49
推荐指数
6
解决办法
18万
查看次数

标签 统计

android ×1

google-maps ×1