Everything About Map
I am new in android programming. I want to know about GPS. I searched and i know a little about this. anyway, i want to use Map, before i used com.google.android.maps.MapView in my
Solution 1:
To start on Google maps, You can refer this link https://developers.google.com/maps/documentation/android/start also MapView is deprecated now, so You have to move with Google Map Version 2.
Example Code : http://www.androidhive.info/2013/08/android-working-with-google-maps-v2/ All the Best..
Solution 2:
You should use Fragment. It is like that on layout;
<fragment
android:name="com.google.android.gms.maps.SupportMapFragment"
android:id="@+id/myMapView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true" />
To use that you should add google-play-services_lib project to your project build path. Then in your class you should implement FragmentActivity like that;
publicclassMainextendsFragmentActivity{
privateGoogleMap mMap;
UiSettings settings;
MapController mapController;
GeoPoint geopoint;
RectF oval;
Canvas canvas;
int mRadius = 5;
@OverrideprotectedvoidonCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setUpMap();
}
@OverrideprotectedvoidonResume(){
super.onResume();
setUpMap();
}
privatevoidsetUpMap(){
if (mMap != null) {
return;
}
mMap=((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.myMapView)).getMap();
if (mMap == null) {
return;
}
mMap.setMyLocationEnabled(true);
mMap.getUiSettings().setCompassEnabled(true);
mMap.getUiSettings().setMyLocationButtonEnabled(true);
mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(place1, 15));
mMap.setTrafficEnabled(true);
mMap.setMapType(GoogleMap.MAP_TYPE_HYBRID);
}
You should obtain an apikey for google maps from this link or you can continue step by step from this link
Add your apikey and permissions to Manifest file like that;
<uses-permissionandroid:name="your_package.permission.MAPS_RECEIVE"/><uses-permissionandroid:name="android.permission.INTERNET" /><uses-permissionandroid:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/><uses-permissionandroid:name="android.permission.ACCESS_FINE_LOCATION"/><meta-dataandroid:name="com.google.android.maps.v2.API_KEY"android:value="your_api_key"/>
Note: meta-data must be inside of application in your manifest.
Post a Comment for "Everything About Map"