Back to project page MapsDemo.
The source code is released under:
Apache License
If you think the Android project MapsDemo listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.infy.dheeraj.mapsdemo; //from w w w .ja va2 s . co m 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.MarkerOptions; import android.app.Activity; import android.app.Fragment; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.LinearLayout; public class GoogleMaps extends Fragment { private Activity act; private View fragView; private LinearLayout mapContainer; private boolean runOnCreate; private GoogleMap map; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { fragView = inflater.inflate(R.layout.maps_fragment, null); mapContainer=(LinearLayout)fragView.findViewById(R.id.containerBox); runOnCreate=true; return fragView; } @Override public void onResume() { if(runOnCreate) { init(); runOnCreate=false; } super.onResume(); } public void moveTo() { if(map==null) return; // new HttpRequestTask().execute(); //"http://maps.googleapis.com/maps/api/geocode/json?address=" map.moveCamera(CameraUpdateFactory.newLatLngZoom( new LatLng(41.889, -87.622), 16)); } public void init() { MapFragment mapFrag=new MapFragment(){ @Override public void onResume() { mapInit(this); super.onResume(); } }; getFragmentManager() .beginTransaction() .add(R.id.containerBox, mapFrag) .commit(); this.act = getActivity(); } protected void mapInit(MapFragment mapFrag) { map = mapFrag.getMap(); LatLng tHq = new LatLng(47.576637, -122.167594); map.setMyLocationEnabled(true); map.moveCamera(CameraUpdateFactory.newLatLngZoom(tHq, 13)); map.addMarker(new MarkerOptions() .title("Welcome to T-Mobile Hq") .snippet( "12920 Southeast 38th Street\n" + "Bellevue, WA 98006\n" + "United States") .position(tHq)); } }