Thursday, December 5, 2013

android using current map location

XML file:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".Currentlocation" >

    <fragment

        android:id="@+id/map"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        class="com.google.android.gms.maps.SupportMapFragment" />


</RelativeLayout>


java file:
public class Currentlocation extends FragmentActivity {
GoogleMap googleMap,map;
MarkerOptions markerOptions;
atLng current_location;
LatLng chennai_central;
@Override
    protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
       setContentView(R.layout.currentlocation);
googleMap = ((SupportMapFragment)(getSupportFragmentManager().findFragmentById(R.id.map))).getMap();
       googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
             current_location = new LatLng(13.06862961, 80.25825799);
       
            markerOptions = new MarkerOptions();
            googleMap.setOnMapClickListener(this);
            googleMap.addMarker(new MarkerOptions()
                    .position(current_location)
                    .title("My Spot")
                    .snippet("This is my spot!")
                    .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE)));
 googleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(current_location, 15));
}
}

Android Manifest:

when u have update your android SDK manager you can mention this code for android manifest

<meta-data android:name="com.google.android.gms.version"

           android:value="@integer/google_play_services_version" />





No comments:

Post a Comment