Tuesday, 21 April 2015

Working With Google Map On Android Studio

Hi!

Working with Android Studio will make some problem when compare with Eclipse IDE, while working on google map we are using V2 & so on.

But in Android Studio Automatically it will generate the Layout file, if you unable to call the marker, do the fallowing by editing your XML & Java file..,


Layout File :

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


Java Class:

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;

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.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;

public class Agent_Track extends FragmentActivity implements OnMapReadyCallback {

    private SupportMapFragment sMapFragment;
    double LLangi,LLatitude;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_agent__track);
        String LL=getIntent().getStringExtra("LLangi");
        String LLe=getIntent().getStringExtra("LLatitude");
        LLangi=Double.valueOf(LL);
        LLatitude=Double.valueOf(LLe);
        sMapFragment = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map));
        sMapFragment.getMapAsync(this);
    }

    @Override
    public void onMapReady(GoogleMap googleMap) {
        LatLng one = new LatLng(10.178, 122.560);
        //LatLng zoomg = new LatLng(10.730278, 122.548889);

        //googleMap.setBuildingsEnabled(true);
        //googleMap.setMyLocationEnabled(true);
        //googleMap.setMapType(GoogleMap.MAP_TYPE_TERRAIN);
        //googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(zoomg , 12));

        googleMap.addMarker(new MarkerOptions()
                .title("Demo Location")
                .snippet("Ha, Ha, Ha..,")
                .position(one)
                .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE)));
    }
}


By edit your xml file you can show your location on Map with Marker..,

Thank You!

Have A Happy Day..,

No comments:

Post a Comment