微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

检测用户何时进入圈子

如何解决检测用户何时进入圈子

我正在开发基于Google地图的应用程序。

我在地图(https://ibb.co/PhZy0t6添加一个圆圈,并且一直试图检测用户是否输入了圆圈

用户是我添加用户当前位置的标记

我试图做到以下几点:

// Circle code:
        circle = mMap.addCircle(new CircleOptions()
                .center(new LatLng(addressLatLng.latitude,addressLatLng.longitude))
                .radius(70)
                .strokeColor(Color.RED)
        );


// The rest

        float[] distance = new float[2];

        Location.distanceBetween(userLocation.latitude,userLocation.longitude,circle.getCenter().latitude,circle.getCenter().longitude,distance);

        if (distance[0] <= circle.geTradius()) {
            Toast.makeText(this,"User Enter Circle",Toast.LENGTH_SHORT).show();

        }

但是没用。

感谢您的帮助

解决方法

所以最后感谢@Axiumin,我做到了:

@Override
public void onLocationChanged(Location location) {


    userLocationMarker.setPosition(new LatLng(location.getLatitude(),location.getLongitude()));


    Location userLocation = new Location("userLocation");
    userLocation.setLatitude(location.getLatitude());
    userLocation.setLongitude(location.getLongitude());

    Location circleLocation = new Location("circleLocation");
    circleLocation.setLatitude(circle.getCenter().latitude);
    circleLocation.setLongitude(circle.getCenter().longitude);


    float distance = userLocation.distanceTo(circleLocation);

    if (distance <= 70){ // If distance is less than 70 Meters


    }



}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。