Skip to content

Instantly share code, notes, and snippets.

@enginebai
Created March 26, 2014 05:39
Show Gist options
  • Save enginebai/9777442 to your computer and use it in GitHub Desktop.
Save enginebai/9777442 to your computer and use it in GitHub Desktop.
MapActivity
import android.app.Activity;
import android.os.Bundle;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
public class MainActivity extends Activity
{
static final LatLng GPS = new LatLng( 25.03880310058, 121.56798553466797 );
private GoogleMap mMap;
@Override
protected void onCreate( Bundle savedInstanceState )
{
super.onCreate( savedInstanceState );
setContentView( R.layout.activity_main );
MapFragment mMapFragment = MapFragment.newInstance();
android.app.FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
fragmentTransaction.add( R.id.map, mMapFragment );
fragmentTransaction.commit();
mMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
Marker marker = mMap.addMarker( new MarkerOptions().position( GPS ) );
mMap.moveCamera( CameraUpdateFactory.newLatLngZoom( GPS, 16 ) );
}
}
@enginebai
Copy link
Author

layout

<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
          android:id="@+id/map"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:name="com.google.android.gms.maps.MapFragment"/>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment