0% found this document useful (0 votes)
2 views

GeoCodingApp

The document contains code for an Android application that integrates Google Maps functionality. It includes an XML layout for the map fragment, a Java activity that initializes the map and retrieves location data using Geocoder, and an AndroidManifest.xml file that declares necessary permissions and application metadata. The app allows users to view a specific location on the map with zoom controls and location markers.

Uploaded by

rupeshpawar214
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

GeoCodingApp

The document contains code for an Android application that integrates Google Maps functionality. It includes an XML layout for the map fragment, a Java activity that initializes the map and retrieves location data using Geocoder, and an AndroidManifest.xml file that declares necessary permissions and application metadata. The app allows users to view a specific location on the map with zoom controls and location markers.

Uploaded by

rupeshpawar214
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

**activity_maps.

xml

<?xml version="1.0" encoding="utf-8"?>


<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MapsActivity" />

**MapsActivity.java

package com.example.geocodingapp;

import android.annotation.SuppressLint;
import android.location.Address;
import android.location.Geocoder;
import android.os.Bundle;
import android.util.Log;

import androidx.fragment.app.FragmentActivity;

import com.example.geocodingapp.databinding.ActivityMapsBinding;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;

import java.io.IOException;
import java.util.List;

public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {

private GoogleMap mMap;


private ActivityMapsBinding binding;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
binding = ActivityMapsBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}
@SuppressLint("MissingPermission")
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
mMap.setMyLocationEnabled(true);
Geocoder oGC=new Geocoder(this);
LatLng latLng=null;
try {
List<Address> list= oGC.getFromLocationName("Pandharpur,Maharashtra,India",1);
Address oAdr=list.get(0);
Log.d("LATIDUDE_VALUE",""+oAdr.getLatitude());
Log.d("LOGITUDE_VALUE",""+oAdr.getLongitude());
latLng=new LatLng(oAdr.getLatitude(),oAdr.getLongitude());
mMap.addMarker(new MarkerOptions().position(latLng).title(oAdr.getLocality()));
mMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
} catch (IOException e) {
throw new RuntimeException(e);
}
mMap.getUiSettings().setZoomControlsEnabled(true);
mMap.getUiSettings().setZoomGesturesEnabled(true);
mMap.getUiSettings().setCompassEnabled(true);
mMap.getUiSettings().setScrollGesturesEnabled(true);
}
}

**AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>


<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.GeoCodingApp"
tools:targetApi="31">
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="AIzaSyB3ToCWeB51xXTS93R-3GkE6t3DL7FdfhU"/>

<activity
android:name=".MapsActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />


</intent-filter>
</activity>
</application>

</manifest>
**Output

You might also like