2015年5月30日 星期六
[Android] google Map API usage 使用方法
google play service 常常變來變去
最近的用法是要滿足以下步驟
1. 加權限
AndroidManifest.xml
// google map
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
// location service
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
2. 加 meta data
<application
android:allowBackup="true"
android:icon="@drawable/logo"
android:label="@string/app_name" >
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="xxxxxxx_your_key" />
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
3. 加 code 這是版本改變導致最大的變化
final GoogleMap map = mapView.getMap();
final float zoomLevel = 16.0f;
m_GoogleApiClient = new GoogleApiClient.Builder(PageNear.this.getActivity())
.addConnectionCallbacks(new GoogleApiClient.ConnectionCallbacks(){
@Override
public void onConnected(Bundle connectionHint) {
// TODO Auto-generated method stub
Log.d("", "");
Location location = LocationServices.FusedLocationApi.getLastLocation(m_GoogleApiClient);
map.moveCamera(CameraUpdateFactory.newLatLngZoom(
new LatLng(location.getLatitude(), location.getLongitude()), zoomLevel));
}
@Override
public void onConnectionSuspended(int cause) {
// TODO Auto-generated method stub
Log.d("", "");
}})
.addOnConnectionFailedListener(new GoogleApiClient.OnConnectionFailedListener(){
@Override
public void onConnectionFailed(ConnectionResult result) {
// TODO Auto-generated method stub
Log.d("", "");
}})
.addApi(LocationServices.API)
.build();
m_GoogleApiClient.connect();
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言