ICP5 - lakshmanamettu/cs5551_team12_icp GitHub Wiki
Class ID:35
Name: Lakshmana Kumar Mettu
Title: To display user’s current location with a marker on the map along with coordinate details (latitude,longitude).
Description: In this wiki I am giving description along with screenshots of output regarding obtaining a current location along with latitude and longitude using google locations through enabling the maps API key.
Source Code : https://github.com/lakshmanamettu/cs5551_team12_icp/tree/master/ICP5/Source
Code & Output Snippets :
Output-1 :
Output-1 having the button Display Location,When we click on it,It will display the current location of the user along with respective latitude and longitude values.
Output-2 :
Output-2 showing the current location of the user with mark.When we click on mark, It will display the Latitude and longitude values which is shown in above picture.
Code Snippet-1:
void getLocation() { if (checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) { LocationManager lc= (LocationManager) getSystemService(Context.LOCATION_SERVICE); Location location = lc.getLastKnownLocation(LocationManager.GPS_PROVIDER); if(location!=null) { LatLng sydney = new LatLng(location.getLatitude(), location.getLongitude()); mMap.addMarker(new MarkerOptions().position(sydney) .title("Latitude : "+location.getLatitude()+", Longitude"+ location.getLongitude())); mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney)); } }
In code snippet-1 I am using the get location function in in order to obtain the location of the user. LocationManager LC=(LocationManager) getSystemService(Context.LOCATION_SERVICE); The above code creates a location manager to get the location updates.The marker is used for indicating locations on the map.
Code Snippet-2 :
<string name="google_maps_key" templateMergeStrategy="preserve" translatable="false"> AIzaSyCVfnb8pz6snvqqhgoq140CZFVbyPu_kaI_ </string>
Code Snippet-2 contains string name as google_maps_key which uses the google map location API key AIzaSyCVfnb8pz6snvqqhgoq140CZFVbyPu_kaI.
Hence it is the required code which is used to obtain the current location of the user along with latitude and longitude values.