在超出半径范围时发出通知google map android

在超出半径范围时发出通知google map android,android,google-maps,Android,Google Maps,如果在解决问题时我不在半径范围内,是否有可能抛出通知 我的模式如下: 我是一名学生,我的手机已经安装了跟踪器。 如果我走进学校范围之外。我的申请将通知我母亲,我已通过短信/电子邮件逃课 你能指引我吗 这是我的密码: protected void onCreate(Bundle savedInstanceState) { mLocationRequest = LocationRequest.create() .setInterval(3)

如果在解决问题时我不在半径范围内,是否有可能抛出通知

我的模式如下: 我是一名学生,我的手机已经安装了跟踪器。 如果我走进学校范围之外。我的申请将通知我母亲,我已通过短信/电子邮件逃课

你能指引我吗

这是我的密码:

protected void onCreate(Bundle savedInstanceState) {
        mLocationRequest = LocationRequest.create()
                .setInterval(3)
                .setFastestInterval(60)
                .setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
        mGoogleApiClient = new GoogleApiClient.Builder(this)
                .addConnectionCallbacks(this)
                .addOnConnectionFailedListener(this)
                .addApi(LocationServices.API)
                .build();
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_student_activity);
}

 public void circle()
 {
    Circle circle = mMap.addCircle(new CircleOptions()
            .center(new LatLng(-xxxxxx,xxxxx))
            .radius(2)
            .strokeColor(Color.RED)
            .strokeWidth(1)
            .fillColor(Color.BLUE));
 }

public void setUpMapIfNeeded()
{
    SupportMapFragment mapFrag = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
    mMap = mapFrag.getMap();
    mMap.setMyLocationEnabled(true);
    circle();
}

public void onConnected(Bundle bundle)
{
    Log.i(TAG,"Location Services Connected.");
    Location location = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);
    if(location==null)
    {
        LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient,mLocationRequest,this);
    }
    else
    {
        handleNewLocation(location);
    }
}

private void handleNewLocation(Location location)
{
    Log.d(TAG,location.toString());
    double currentLatitude = location.getLatitude();
    double currentLongitude = location.getLongitude();
    LatLng latLng = new LatLng(currentLatitude,currentLongitude);
    MarkerOptions options = new MarkerOptions()
            .position(latLng)
            .title("I am here !");
    mMap.addMarker(options);
    mMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
    mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(latLng,21));
}

public void onLocationChanged(Location location) {
    handleNewLocation(location);
}

//将此代码放入新位置

//put this code in handler new location
if(distanceBetween(current_latlon, circle_latlon)>radius_of_circle)//radius in meters
{
    //here you can create a notification of whatever you want
}

//to calculate distance between two latlong
private float distanceBetween(LatLng latLng1, LatLng latLng2) 
{
    Location loc1 = new Location(LocationManager.GPS_PROVIDER);
        Location loc2 = new Location(LocationManager.GPS_PROVIDER);
        loc1.setLatitude(latLng1.latitude);
        loc1.setLongitude(latLng1.longitude);
        loc2.setLatitude(latLng2.latitude); 
        loc2.setLongitude(latLng2.longitude);
        return loc1.distanceTo(loc2);       //in meters
    }

查看地理围栏API或邻近警报API的任何链接或关键字?它来自何处:当前_latlon和圆_latlon和圆的半径_?我还是新手。Tehee1。在你的public void circle()函数中有一个类似于latlon的新latlon(-xxxxx,xxxx)是你的圆_latlon,2.当前_latlon是public void onLocationChanged(location-location)函数中的位置变量,3。圆的半径是您在public void circle()方法中提到的任何东西;在if语句中输入如下内容:if(distanceBetween(latLng,latlngcircle)>5{sendsms();}当我在手机中调试时,它变成了一次又一次地重新启动程序。解决方案是什么?