如何在附近100米半径范围内显示地点? [英] How to show places only in 100 meter radius nearby user ?

查看:127
本文介绍了如何在附近100米半径范围内显示地点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

获取位置的代码



  public   void  getMyLocation(活动活动){
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 = 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(),);


}





代码为LAT& LNG



  public 地址getLocationFromLatLng(上下文上下文,LatLng latLng){ 
android.location.Geocoder geoCoder = new Geocoder(context,Locale.getDefault());

尝试 {
return geoCoder.getFromLocation(latLng.latitude ,latLng.longitude, 1 )。 get 0 < /跨度>);
} catch (IOException e){
return ;
}

}





但问题是

引用:



什么时候我会得到替身&我将如何展示距离该附近仅100米半径的地方。 lng用户?





我尝试过:



我试图只显示附近100米的地方,但它也显示不同的街道位置,也不在那个半径

解决方案

学习创建和监控地理围栏| Android开发者 [ ^ ]

Code for get Location

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);


}



CODE FOR LAT & LNG

 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;
    }

}



But the problem is

Quote:


when i will get latitute & longitute .. how i will show only 100 meter radius places that is nearby that lat & lng of user ?



What I have tried:

I tried to show only 100 meter nearby places but it also showing different street places that not also in that radius

解决方案

Learn Creating and Monitoring Geofences | Android Developers[^]


这篇关于如何在附近100米半径范围内显示地点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆