Display Map Markers from Lat Lon

528 views Asked by At

I am learning android. Right now I am working on an app that uses map api. So far I did the following: - I long clicked the map and opened a new activityClickedMap displaying lat and lon of the location I clicked - I clicked save button and added lat and lon, both to server and to my local db

The thing I want to do is this: - When I open the map I want it to display a marker using the lat and the lon from database

2

There are 2 answers

0
Avinash Mishra On BEST ANSWER

Retrieve lat and long from database.

String  latfromdb , longfromdb ;

and then

LatLng latLng = new LatLng(Double.parseDouble(latfromdb),Double.parseDouble(longfromdb));

 MarkerOptions optionss = new MarkerOptions()
                    .alpha(1)
                    .flat(false)
                    .position(latLng)
                    .icon(BitmapDescriptorFactory.fromResource(R.drawable.pin));
            googleMap.addMarker(optionss);
            googleMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
            googleMap.animateCamera(CameraUpdateFactory.zoomTo(15));

Get the list of lat long from db and Add Marker in for loop for multiple marker :

MarkerOptions optionss = new MarkerOptions()
                    .alpha(1)
                    .flat(false)
                    .position(latLng)
                    .icon(BitmapDescriptorFactory.fromResource(R.drawable.pin));
            googleMap.addMarker(optionss);
0
RedCollarPanda On

Have a look at

https://developers.google.com/maps/documentation/android-api/marker?hl=en

So the thing is - you get coords from db and put them all to your map.