Android Google Map Displaying Current LocationIn the previous tutorial of Android Google Map, we simply displayed the default coordinates (location) set by the MapsActivity.java class file. Now in this tutorial we will display and place marker at the user current location. For doing this we need to generate Google Map API key. The process of generating Google Map API is described in tutorial Android Google Map. To display the user current location we need to implements some interfaces and there callbacks methods. Callback methods in Google Map
The setMyLocationEnabled() method of GoogleMap is used to enable location layer, which allows device to interact with current location. Example of Google Map Displaying Current LocationLet's see an example of Google Map which displays the current location of device. activity_maps.xmlAdd a SupportMapFragment in fragment in activity_maps.xml file. build.gradelAdd the following dependencies in build.gradel file. MapsActivity.javaAdd the following code in MapsActivity.java file. Request Runtime PermissionAndroid device having Android 6.0 (Marshmallow) or later are required some permission at runtime to access device functionality. In the above MapsActivity.java file we added a runtime permission Manifest.permission.ACCESS_FINE_LOCATION which request to access device location. The runtime permission is checked using checkSelfPermission() method and return PackageManager.PERMISSION_GRANTED or PackageManager.PERMISSION_DENIED. If permission granted than app proceeds for operation. Required Permission in AndroidManifest.xmlAdd the following user-permission in AndroidManifest.xml file. AndroidManifest.xmlOutput
Next TopicAndroid Google Map Search Location
|