Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/245.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android地图显示我的位置';行不通_Android_Emulation - Fatal编程技术网

Android地图显示我的位置';行不通

Android地图显示我的位置';行不通,android,emulation,Android,Emulation,我一直在努力获取谷歌地图中的当前位置,我甚至尝试了官方地图演示,但也不起作用。它在右上角显示了getmylocation按钮,但在地图上没有显示任何蓝点,这是我当前的位置。 这是我的代码,我使用的是emulator target api 23,我想这可能是emulator的问题,因为我直接从github下载的代码。 任何建议都将不胜感激。[截图][1] package com.example.mapdemo; import com.google.android.gms.maps.

我一直在努力获取谷歌地图中的当前位置,我甚至尝试了官方地图演示,但也不起作用。它在右上角显示了getmylocation按钮,但在地图上没有显示任何蓝点,这是我当前的位置。 这是我的代码,我使用的是emulator target api 23,我想这可能是emulator的问题,因为我直接从github下载的代码。 任何建议都将不胜感激。[截图][1]

    package com.example.mapdemo;
    import com.google.android.gms.maps.GoogleMap;
    import com.google.android.gms.maps.GoogleMap.OnMyLocationButtonClickListener;
    import com.google.android.gms.maps.OnMapReadyCallback;
    import com.google.android.gms.maps.SupportMapFragment;

    import android.Manifest;
    import android.content.pm.PackageManager;
    import android.os.Bundle;
    import android.support.annotation.NonNull;
    import android.support.v4.app.ActivityCompat;
    import android.support.v4.content.ContextCompat;
    import android.support.v7.app.AppCompatActivity;
    import android.widget.Toast;

    /**
     * This demo shows how GMS Location can be used to check for changes to the users location.  The
     * "My Location" button uses GMS Location to set the blue dot representing the users location.
     * Permission for {@link android.Manifest.permission#ACCESS_FINE_LOCATION} is requested at run
     * time. If the permission has not been granted, the Activity is finished with an error message.
     */
    public class MyLocationDemoActivity extends AppCompatActivity
            implements
            OnMyLocationButtonClickListener,
            OnMapReadyCallback,
            ActivityCompat.OnRequestPermissionsResultCallback {

        /**
         * Request code for location permission request.
         *
         * @see #onRequestPermissionsResult(int, String[], int[])
         */
        private static final int LOCATION_PERMISSION_REQUEST_CODE = 1;

        /**
         * Flag indicating whether a requested permission has been denied after returning in
         * {@link #onRequestPermissionsResult(int, String[], int[])}.
         */
        private boolean mPermissionDenied = false;

        private GoogleMap mMap;

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

            SupportMapFragment mapFragment =
                    (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
            mapFragment.getMapAsync(this);
        }

        @Override
        public void onMapReady(GoogleMap map) {
            mMap = map;

            mMap.setOnMyLocationButtonClickListener(this);
            enableMyLocation();
        }

        /**
         * Enables the My Location layer if the fine location permission has been granted.
         */
        private void enableMyLocation() {
            if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION)
                    != PackageManager.PERMISSION_GRANTED) {
                // Permission to access the location is missing.
                PermissionUtils.requestPermission(this, LOCATION_PERMISSION_REQUEST_CODE,
                        Manifest.permission.ACCESS_FINE_LOCATION, true);
            } else if (mMap != null) {
                // Access to the location has been granted to the app.
                mMap.setMyLocationEnabled(true);
            }
        }

        @Override
        public boolean onMyLocationButtonClick() {
            Toast.makeText(this, "MyLocation button clicked", Toast.LENGTH_SHORT).show();
            // Return false so that we don't consume the event and the default behavior still occurs
            // (the camera animates to the user's current position).
            return false;
        }


        @Override
        public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
                @NonNull int[] grantResults) {
            if (requestCode != LOCATION_PERMISSION_REQUEST_CODE) {
                return;
            }

            if (PermissionUtils.isPermissionGranted(permissions, grantResults,
                    Manifest.permission.ACCESS_FINE_LOCATION)) {
                // Enable the my location layer if the permission has been granted.
                enableMyLocation();
            } else {
                // Display the missing permission error dialog when the fragments resume.
                mPermissionDenied = true;
            }
        }

        @Override
        protected void onResumeFragments() {
            super.onResumeFragments();
            if (mPermissionDenied) {
                // Permission was not granted, display error dialog.
                showMissingPermissionError();
                mPermissionDenied = false;
            }
        }

        /**
         * Displays a dialog with error message explaining that the location permission is missing.
         */
        private void showMissingPermissionError() {
            PermissionUtils.PermissionDeniedDialog
                    .newInstance(true).show(getSupportFragmentManager(), "dialog");
        }

    }

**strong text**
  [1]: http://i.stack.imgur.com/YDhk2.png

第一次将新图像用于模拟器时,没有任何位置坐标保存到设备,也没有使用计算机的位置

单击右侧边栏上的“更多”选项,这将打开“扩展控件”窗口。选择“位置”选项卡(默认情况下应选中),根据您的心愿更改纬度和经度输入,然后单击“发送”。瞧