I followed the tutorial in
https://developers.google.com/maps/documentation/android/start
and i managed to load a map into my app.Now i want to add some markers into my app using latitudes and longitudes.How do i do it? I tried something but did not work. The code i tried is below.
This how i was going to do it.But i get a null point exception.What is the reason for that?
GoogleMap googleMap = null;
MapFragment fm = (MapFragment) (activity.getFragmentManager())
.findFragmentById(R.id.map);
googleMap = fm.getMap();
double latitude = 7.421226;
double longitude =80.401264 ;
// create marker
MarkerOptions marker = new MarkerOptions().position(new LatLng(latitude, longitude)).title("Hello Maps ");
// adding marker
googleMap.addMarker(marker);
My layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="@+id/filmhall"
android:background="@color/grey" >
<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.google.android.gms.maps.SupportMapFragment"/>
</LinearLayout>