How to save the coordinates of a circle of google maps in the database?

3

As I can save the coordinates of a circle of google maps in the database, I already load the map and with the function onMapLongClickListener it allows to draw a new circle to the user. Now what I would like to do is to be able to store those values. And so far I did not find any link to help me

    
asked by Ana Rotela Cabrera 02.07.2016 в 02:25
source

1 answer

1

This way a circle is created in the Google map api v3 of Android. Assuming you already know how to communicate with your database.

Circle circle = map.addCircle(new CircleOptions()
     .center(new LatLng(-33.87365, 151.20689))
     .radius(10000)
     .strokeColor(Color.RED)
     .fillColor(Color.BLUE));

As you can see, you have the following values to save in order to redraw the circle: new LatLng(-33.87365, 151.20689) and radius(1000) .

Therefore you will keep the following three elements of the circle captured by the user in your Database.

double latitud = circle.getCenter().latitude;
double longitud = circle.getCenter().longitude;
double radio = circle.getRadius();

guardarCircleEnBaseDeDatos(latitud,longitud,radio);

Later, as we saw in the beginning, you can draw the circles with their coordinates and their radius.

    //Creas un objeto circulo de una clase creada previamente por ti para facilitar el trabajo.
    Circulo circulo = ObtenerCirculoDeBD();

    double latitud = circulo.getLatitud();
    double longitud = circulo.getLongitud();
    double radio = circulo.getRadio();

    Circle miCirculoDeLaBD = map.addCircle(new CircleOptions()
             .center(new LatLng(latitud , longitud))
             .radius(radio)
             .strokeColor(Color.RED)
             .fillColor(Color.BLUE));
  

I leave the documentation,    link .

    
answered by 02.07.2016 в 09:43