Maps 谷歌地图-显示当前位置坐标

Maps 谷歌地图-显示当前位置坐标,maps,coordinates,Maps,Coordinates,我想在地图上显示我当前位置的坐标。这是代码,但它不能正常工作。它只显示定义参数内的地图,但当我点击显示我当前位置的按钮时,什么也没发生。 我使用网络上的Android Studio教程编写了这段代码。 我正在使用Android studio,只是一个新的学习者 这也是我在智能手机上运行应用程序时在事件日志中得到的信息: 21:56:48无法为调试器绑定到本地8600 21:56:49主机中的软件中止了已建立的连接 java.io.IOException:主机中的软件中止了已建立的连接 位于sun

我想在地图上显示我当前位置的坐标。这是代码,但它不能正常工作。它只显示定义参数内的地图,但当我点击显示我当前位置的按钮时,什么也没发生。 我使用网络上的Android Studio教程编写了这段代码。 我正在使用Android studio,只是一个新的学习者

这也是我在智能手机上运行应用程序时在事件日志中得到的信息:

21:56:48无法为调试器绑定到本地8600
21:56:49主机中的软件中止了已建立的连接
java.io.IOException:主机中的软件中止了已建立的连接 位于sun.nio.ch.SocketDispatcher.write0(本机方法) 在sun.nio.ch.SocketDispatcher.write中(SocketDispatcher.java:51) 位于sun.nio.ch.IOUtil.writeFromNativeBuffer(IOUtil.java:93) 位于sun.nio.ch.IOUtil.write(IOUtil.java:65) 在sun.nio.ch.SocketChannelImpl.write(SocketChannelImpl.java:487) 在com.android.ddmlib.JdwpPacket.writeAndConsume(JdwpPacket.java:213)上 在com.android.ddmlib.Client.sendAndConsume上(Client.java:686) 位于com.android.ddmlib.HandleHeap.sendREAQ(HandleHeap.java:349) 位于com.android.ddmlib.Client.requestAllocationStatus(Client.java:525) 位于com.android.ddmlib.DeviceMonitor.createClient(DeviceMonitor.java:569) 位于com.android.ddmlib.DeviceMonitor.openClient(DeviceMonitor.java:544) 在com.android.ddmlib.DeviceMonitor.deviceClientMonitorLoop(DeviceMonitor.java:360)上 在com.android.ddmlib.Devic


“工作不正常”的确切含义是什么?应用程序仅显示地图,就像上面代码中初始化的一样,并显示当前位置,我想在文本标签中获取当前位置坐标。@vesan请查看问题的最后一次编辑
<?xml version="1.0" encoding="utf-8"?>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">


    <meta-data
        android:name="com.google.android.geo.API_KEY"
        android:value="@string/google_maps_key" />

    <activity
        android:name=".MapsActivity_koordinate"
        android:label="@string/title_activity_maps">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <meta-data
        android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />
</application>
    package com.example.apollo.kartamackovec;

    import android.location.Location;
    import android.net.Uri;
    import android.support.v4.app.FragmentActivity;
    import android.os.Bundle;
    import android.widget.TextView;
    import android.widget.Toast;

    import com.google.android.gms.appindexing.Action;
    import com.google.android.gms.appindexing.AppIndex;
    import com.google.android.gms.common.ConnectionResult;
    import com.google.android.gms.common.api.GoogleApiClient;
    import com.google.android.gms.location.LocationServices;
    import com.google.android.gms.maps.CameraUpdateFactory;
    import com.google.android.gms.maps.GoogleMap;
    import com.google.android.gms.maps.OnMapReadyCallback;
    import com.google.android.gms.maps.SupportMapFragment;
    import com.google.android.gms.maps.model.LatLng;
    import com.google.android.gms.maps.model.MarkerOptions;

    public class MapsActivity_koordinate extends FragmentActivity implements     GoogleApiClient.ConnectionCallbacks,GoogleApiClient.OnConnectionFailedListener, OnMapReadyCallback, MapsActivity {

    public GoogleMap mMap;

    public GoogleApiClient client;
    public TextView mLongitudeText;
    public TextView mLatitudeText;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_maps);
        // Obtain the SupportMapFragment and get notified when the map is ready to be used.
        SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
                .findFragmentById(R.id.map);
        mapFragment.getMapAsync(this);
        // ATTENTION: This was auto-generated to implement the App Indexing API.
        // See https://g.co/AppIndexing/AndroidStudio for more information.
        client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
    }


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


        LatLng mackovec = new LatLng(46.4239, 16.4339);
        mMap.addMarker(new MarkerOptions().position(mackovec).title("Marker u Mačkovcu"));
        mMap.moveCamera(CameraUpdateFactory.newLatLng(mackovec));
        mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(mackovec, 18));
        mMap.setMapType(GoogleMap.MAP_TYPE_HYBRID);
        mMap.setMyLocationEnabled(true);
        }
        @Override
        public void onConnected(Bundle connectionHint) {
        Location mLastLocation = LocationServices.FusedLocationApi.getLastLocation(client);
        if (mLastLocation != null) {
            mLatitudeText.setText(String.valueOf(mLastLocation.getLatitude()));
            mLongitudeText.setText(String.valueOf(mLastLocation.getLongitude()));
            Toast.makeText(this, "Location " + mLatitudeText+","+mLongitudeText,
                    Toast.LENGTH_LONG).show();

        } else {
            Toast.makeText(this, "noconnection",
                    Toast.LENGTH_LONG).show();
        }

    }

    @Override
    public void onConnectionSuspended(int i) {

    }

    @Override
        public void onStart() {
            client.connect();
            super.onStart();

            // ATTENTION: This was auto-generated to implement the App Indexing API.
            // See https://g.co/AppIndexing/AndroidStudio for more information.
            client.connect();
            Action viewAction = Action.newAction(
                    Action.TYPE_VIEW, // TODO: choose an action type.
                    "Main Page", // TODO: Define a title for the content shown.
                    // TODO: If you have web page content that matches this app activity's content,
                    // make sure this auto-generated web page URL is correct.
                    // Otherwise, set the URL to null.
                    Uri.parse("http://host/path"),
                    // TODO: Make sure this auto-generated app deep link URI is correct.
                    Uri.parse("android-app://com.example.apollo.kartamackovec/http/host/path")
            );
            AppIndex.AppIndexApi.start(client, viewAction);
        }

        @Override
        public void onStop() {
            client.disconnect();
            super.onStop();

            // ATTENTION: This was auto-generated to implement the App Indexing API.
            // See https://g.co/AppIndexing/AndroidStudio for more information.
            Action viewAction = Action.newAction(
                    Action.TYPE_VIEW, // TODO: choose an action type.
                    "Main Page", // TODO: Define a title for the content shown.
                    // TODO: If you have web page content that matches this app activity's content,
                    // make sure this auto-generated web page URL is correct.
                    // Otherwise, set the URL to null.
                    Uri.parse("http://host/path"),
                    // TODO: Make sure this auto-generated app deep link URI is correct.
                    Uri.parse("android-app://com.example.apollo.kartamackovec/http/host/path")
            );
            AppIndex.AppIndexApi.end(client, viewAction);
            client.disconnect();
        }

    @Override
    public void onConnectionFailed(ConnectionResult connectionResult) {
        Toast.makeText(this, "noconnection",
                Toast.LENGTH_LONG).show();
    }
}