问题
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 project but now i want to know everything about Map.What are ways for using map in project except above way? Can i use com.google.android.maps.MapView
in my project but i dont connect to internet? I mean what are ways for showing map and searching on map with offline way?
I searched but i cant get answer of full of my questions :( Thanks for advise.
回答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..
回答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;
public class Main extends FragmentActivity{
private GoogleMap mMap;
UiSettings settings;
MapController mapController;
GeoPoint geopoint;
RectF oval;
Canvas canvas;
int mRadius = 5;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setUpMap();
}
@Override
protected void onResume(){
super.onResume();
setUpMap();
}
private void setUpMap(){
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-permission android:name="your_package.permission.MAPS_RECEIVE"/>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="your_api_key"/>
Note: meta-data must be inside of application in your manifest.
来源:https://stackoverflow.com/questions/20265265/everything-about-map