Reputation: 527
I'm working on an app that sends messages from Admin to Clients. The flow is very simple - Admin types a message, and every client that has this app installed receives that message. I'm using pooling (not push notifications for now).
The sending/receiving message is working fine, and now I need to add new feature: Admin chooses an area on the map (Google maps api v2), and the client checks his location and shows the message only if he is inside the marked area.
So far, I accomplished only the visual part of selecting an area in the screen : There is a circle (admin can change circles radius) around the point where admin clicks, and now I have to do the tricky part -mark the the area inside the circle and send it to the DB (with the message) so the other side (the client) will check if his position is inside the circle, and should he receive the message.
Any help?
I attached relevant code block and a screen snap.
code:
private void drawCircle(LatLng center, int radius) {
CircleOptions circleOptions = new CircleOptions().center(center).radius(radius);
circleOptions.strokeColor(Color.BLUE);
circleOptions.strokeWidth(3);
gMap.addCircle(circleOptions);
Log.d(TAG, "center = " + center.latitude + " , " + center.longitude);
Log.d(TAG, "radius = " + radius);
gMap.addMarker(new MarkerOptions().position(center).icon(BitmapDescriptorFactory.fromResource(R.drawable.dot)) );
}
Thanks...
Upvotes: 2
Views: 1253
Reputation: 1185
I think that the simplest thing you need to do, is check the distance between the client and the center of the circle. If it's less than circle's radius -> the client is inside.
Upvotes: 1