1 Add Library
2 Create XML + Create Google Console API
<string name="map_key" translatable="false">
AIzaSyBOac3YAZEtsJaUHLeajuzs1awQJk2qnbY
AIzaSyBOac3YAZEtsJaUHLeajuzs1awQJk2qnbY
2 Manifest Permissions
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"></uses-permission> <uses-permission android:name="android.permission.INTERNET"/>
<meta-data android:name="com.google.android.geo.API_KEY" android:value="@string/map_key" />
3 Create Fragment in XML
<fragment android:id="@+id/map" android:layout_width="match_parent" android:layout_height="match_parent" android:name="com.google.android.gms.maps.SupportMapFragment"> </fragment>
4 Java File Coding
public class MainActivity extends FragmentActivity implements OnMapReadyCallback { GoogleMap map;
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager() .findFragmentById(R.id.map); mapFragment.getMapAsync(this);
@Override public void onMapReady(GoogleMap googleMap) { map = googleMap; LatLng Pakistan = new LatLng(-33.852, 151.211); map.addMarker(new MarkerOptions().position(Pakistan).title("Pakistan")); map.moveCamera(CameraUpdateFactory.newLatLng(Pakistan)); } }
Google Map Types
- Nomal Type + Hybrid Type + Terrin & Satellite
0 comments:
Post a Comment