0
我想知道用户通过gps的街道名称或地址,然后我可以在那里放置半径例如100米或长,并显示特定区域的商店,食物的地方等。谁能告诉我如何在google map v2中获取当前位置信息?
我想知道用户通过gps的街道名称或地址,然后我可以在那里放置半径例如100米或长,并显示特定区域的商店,食物的地方等。谁能告诉我如何在google map v2中获取当前位置信息?
代码来获得用户
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);
}
此代码的位置,从经纬度
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;
}
}
获得地址,你必须在谷歌API控制台 注册该应用程序的代码for Android 6.0 plus pay attation to the listeners .. 这是一个工作代码。
我什么时候会得到结婚和结婚..我怎样才能展示只有100米左右的地方附近那个纬度&lng – user3218829
感谢您的代码 – user3218829
使用“附近的搜索请求”[https://developers.google .com/maps/documentation/javascript/places#place_search_requests],通过调用PlacesService的nearbySearch()方法启动Places Nearby搜索,该方法将返回一组PlaceResult对象。包含'位置'和'半径'以表示圆的半径(以米为单位)。 –