我只是尝试使用android中的googlemaps v2。当我运行它没有错误但地图不能显示我从lat和long设置的地方(显示空白区域)。谁能告诉我我的想法?非常感谢你。
这是logcat
12-04 16:36:59.545: D/AbsListView(564): Get MotionRecognitionManager
12-04 16:36:59.545: D/AbsListView(564): onVisibilityChanged() is called, visibility : 8
12-04 16:36:59.550: D/AbsListView(564): unregisterIRListener() is called
12-04 16:36:59.550: D/AbsListView(564): onVisibilityChanged() is called, visibility : 8
12-04 16:36:59.550: D/AbsListView(564): unregisterIRListener() is called
12-04 16:36:59.560: D/AbsListView(564): onVisibilityChanged() is called, visibility : 0
12-04 16:36:59.560: D/AbsListView(564): unregisterIRListener() is called
12-04 16:36:59.575: D/AbsListView(564): onVisibilityChanged() is called, visibility : 4
12-04 16:36:59.575: D/AbsListView(564): unregisterIRListener() is called
12-04 16:36:59.585: D/AbsListView(564): onVisibilityChanged() is called, visibility : 0
12-04 16:36:59.585: D/AbsListView(564): unregisterIRListener() is called
12-04 16:36:59.650: D/AbsListView(564): unregisterIRListener() is called
12-04 16:36:59.710: D/dalvikvm(564): GC_FOR_ALLOC freed 219K, 52% free 5537K/11424K, paused 18ms, total 18ms
12-04 16:36:59.710: I/dalvikvm-heap(564): Grow heap (frag case) to 10.748MB for 131088-byte allocation
12-04 16:36:59.725: D/dalvikvm(564): GC_FOR_ALLOC freed <1K, 51% free 5664K/11556K, paused 18ms, total 18ms
12-04 16:36:59.750: E/dalvikvm(564): adjustAdaptiveCoef max=8388608, min=2097152, ut=568
12-04 16:36:59.750: D/AbsListView(564): [unregisterDoubleTapMotionListener]
12-04 16:36:59.750: D/dalvikvm(564): GC_FOR_ALLOC freed 152K, 53% free 5536K/11556K, paused 20ms, total 20ms
12-04 16:36:59.750: I/MotionRecognitionManager(564): .unregisterListener : / listener count = 0->0,
12-04 16:36:59.750: D/AbsListView(564): unregisterIRListener() is called
12-04 16:37:13.520: D/dalvikvm(564): GC_CONCURRENT freed 2060K, 58% free 5398K/12804K, paused 5ms+6ms, total 46ms
12-04 16:37:24.595: D/AbsListView(564): unregisterIRListener() is called
12-04 16:37:24.735: D/AbsListView(564): onVisibilityChanged() is called, visibility : 8
12-04 16:37:24.735: D/AbsListView(564): unregisterIRListener() is called
12-04 16:37:24.750: D/AbsListView(564): onDetachedFromWindow
12-04 16:37:31.665: D/dalvikvm(564): GC_CONCURRENT freed 408K, 58% free 5385K/12804K, paused 9ms+4ms, total 71ms
12-04 16:37:31.665: D/AbsListView(564): [unregisterDoubleTapMotionListener]
12-04 16:37:31.665: I/MotionRecognitionManager(564): .unregisterListener : / listener count = 0->0,
12-04 16:50:04.020: E/dalvikvm(564): adjustAdaptiveCoef max=8388608, min=2097152, ut=568
12-04 16:37:31.665: D/AbsListView(564): unregisterIRListener() is called
这是我的主要活动
package unai.skripsi.mymaps;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.Menu;
public class MainActivity extends FragmentActivity {
static final LatLng RAGUNAN = new LatLng(-6.3039, 106.8267);
static final LatLng TAMANMINI = new LatLng(-6.29436, 106.8859);
private GoogleMap map;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
map= ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
if (map!=null){
Marker ragunan = map.addMarker(new MarkerOptions().position(RAGUNAN)
.title("Ragunan"));
Marker tamanmini = map.addMarker(new MarkerOptions().position(TAMANMINI)
.title("Taman mini")
.snippet("Taman mini itu indah")
.icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_launcher)));
map.moveCamera(CameraUpdateFactory.newLatLngZoom(RAGUNAN, 15));
map.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null);
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
这是我的AndroidManifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="unai.skripsi.mymaps"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<permission
android:name="unai.skripsi.mymaps.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="unai.skripsi.mymaps.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="unai.skripsi.mymaps.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaKlACQ2LD6E2jd_AUDWLMB2AsasdwdadAsSRT" />
</application>
</manifest>
这是我的布局activity_main
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.google.android.gms.maps.SupportMapFragment" />
</RelativeLayout>
答案 0 :(得分:0)
转到google api控制台并启用Google Maps Android API v2服务