Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/197.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 如何在google map v2中获取当前位置信息?_Android_Google Maps - Fatal编程技术网

Android 如何在google map v2中获取当前位置信息?

Android 如何在google map v2中获取当前位置信息?,android,google-maps,Android,Google Maps,我想通过gps知道用户的街道名称或地址,这样我就可以把半径放在那里,例如100米或更长,并显示特定区域的商店、食品店等。。!有人能告诉我获取用户位置的代码吗 public void getMyLocation(Activity activity) { int requestPermissionsCode = 50; LocationManager locationManager = (LocationManager) activity.getSystemService(Con

我想通过gps知道用户的街道名称或地址,这样我就可以把半径放在那里,例如100米或更长,并显示特定区域的商店、食品店等。。!有人能告诉我获取用户位置的代码吗

  public void getMyLocation(Activity activity) {
    int requestPermissionsCode = 50;
    LocationManager locationManager = (LocationManager) activity.getSystemService(Context.LOCATION_SERVICE);
    if (ActivityCompat.checkSelfPermission(activity, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(activity, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
        ActivityCompat.requestPermissions(activity, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, requestPermissionsCode);
        return;
    }
    Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
    if (location != null) {
        LatLng latLng = new LatLng(location.getLatitude(), location.getLongitude());
        if (locationListener != null)
            locationListener.onLocationFound(latLng);
        return;
    }


    locationManager.requestSingleUpdate(LocationManager.GPS_PROVIDER, new SingleUpdateListener(), null);


}
此代码用于从LatLng获取地址

  public Address getLocationFromLatLng(Context context, LatLng latLng) {
    android.location.Geocoder geoCoder = new Geocoder(context, Locale.getDefault());

    try {
        return geoCoder.getFromLocation(latLng.latitude, latLng.longitude, 1).get(0);
    } catch (IOException e) {
        return null;
    }

}
您必须在Google API控制台上注册应用程序 代码是针对Android 6.0的 再加上对听众的重视。。
这是一个有效的代码。

我什么时候能拿到拉提图和朗吉图。。我将如何仅显示lat附近100米半径的位置(&L)使用“附近搜索请求”[,通过调用PlacesService的nearbySearch()方法启动附近位置搜索,该方法将返回PlaceResult对象数组。包括“位置”和“半径”以米表示圆的半径。