谷歌地图不会出现在我的Android设备上。我做的一切都很对。我从命令提示符创建了证书指纹。 然后我从我的Google控制台获得了地图API密钥,并且我在Manifest.XML中提供了所有权限,包括在活动中放入的API密钥
我检查了一切,但为什么地图没有在我的设备上显示。
Android Manifest.XML
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.justsee.androidapi" >
<permission
android:name="com.justsee.androidapi.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="com.justsee.androidapi.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<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" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".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="AIza**************************" />
<uses-library android:name="com.google.android.maps" />
</application>
</manifest>
activity_main.xml中
<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" >
<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.MapFragment" />
Main_activity.java
import android.support.v7.app.ActionBarActivity;
import java.util.ArrayList;
import java.util.List;
import android.app.Activity;
import android.os.Bundle;
import com.google.android.gms.maps.CameraUpdate;
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.LatLngBounds;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
public class MainActivity extends ActionBarActivity {
private GoogleMap map;
LatLngBounds.Builder builder;
CameraUpdate cu;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map))
.getMap();
/**call the map set up method*/
mSetUpMap();
}
public void mSetUpMap() {
/**clear the map before redraw to them*/
map.clear();
/**Create dummy Markers List*/
List<Marker> markersList = new ArrayList<Marker>();
Marker Delhi = map.addMarker(new MarkerOptions().position(new LatLng(
28.61, 77.2099)).title("Delhi"));
Marker Chaandigarh = map.addMarker(new MarkerOptions().position(new LatLng(
30.75, 76.78)).title("Chandigarh"));
Marker SriLanka = map.addMarker(new MarkerOptions().position(new LatLng(
7.000, 81.0000)).title("Sri Lanka"));
Marker America = map.addMarker(new MarkerOptions().position(new LatLng(
38.8833, 77.0167)).title("America"));
Marker Arab = map.addMarker(new MarkerOptions().position(new LatLng(
24.000, 45.000)).title("Arab"));
/**Put all the markers into arraylist*/
markersList.add(Delhi);
markersList.add(SriLanka);
markersList.add(America);
markersList.add(Arab);
markersList.add(Chaandigarh);
/**create for loop for get the latLngbuilder from the marker list*/
builder = new LatLngBounds.Builder();
for (Marker m : markersList) {
builder.include(m.getPosition());
}
/**initialize the padding for map boundary*/
int padding = 50;
/**create the bounds from latlngBuilder to set into map camera*/
LatLngBounds bounds = builder.build();
/**create the camera with bounds and padding to set into map*/
cu = CameraUpdateFactory.newLatLngBounds(bounds, padding);
/**call the map call back to know map is loaded or not*/
map.setOnMapLoadedCallback(new GoogleMap.OnMapLoadedCallback() {
@Override
public void onMapLoaded() {
/**set animated zoom camera into map*/
map.animateCamera(cu);
}
});
}
}
Logcat:
04-20 12:51:18.761 11173-11173/com.justsee.googlemapapi W/Typeface﹕ getVibeFontPathWithCTS(): fontPath =
04-20 12:51:18.761 11173-11173/com.justsee.googlemapapi W/Typeface﹕ getVibeFontPathWithCTS(): fontName =
04-20 12:51:18.761 11173-11173/com.justsee.googlemapapi W/Typeface﹕ getVibeFontPathWithCTS(): isForceToSystemDefault = false
04-20 12:51:18.761 11173-11173/com.justsee.googlemapapi W/Typeface﹕ VIBEUI_setThemeFont(): sVibeFontPath = ,fontPath =
04-20 12:51:18.761 11173-11173/com.justsee.googlemapapi W/Typeface﹕ VIBEUI_setThemeFont(): FontPath Not Changed!
04-20 12:51:18.765 11173-11173/com.justsee.googlemapapi D/wangcy9﹕ setStatusIcon occur wrong theme!
04-20 12:51:18.747 11173-11173/com.justsee.googlemapapi V/ActivityThread﹕ Handling launch of ActivityRecord{50ef897 token=android.os.BinderProxy@12e80a84 {com.justsee.googlemapapi/com.justsee.googlemapapi.MainActivity}}
04-20 12:51:18.747 11173-11173/com.justsee.googlemapapi V/ActivityThread﹕ ActivityRecord{50ef897 token=android.os.BinderProxy@12e80a84 {com.justsee.googlemapapi/com.justsee.googlemapapi.MainActivity}}: app=android.app.Application@3fd837c3, appName=com.justsee.googlemapapi, pkg=com.justsee.googlemapapi, comp={com.justsee.googlemapapi/com.justsee.googlemapapi.MainActivity}, dir=/data/app/com.justsee.googlemapapi-1/base.apk
04-20 12:51:18.778 11173-11173/com.justsee.googlemapapi I/Google Maps Android API﹕ Google Play services package version: 8703248
04-20 12:51:18.801 11173-11173/com.justsee.googlemapapi D/AbsListView﹕ checkAbsListViewlLogProperty get invalid command
04-20 12:51:18.823 11173-11173/com.justsee.googlemapapi V/ActivityThread﹕ Performing resume of ActivityRecord{50ef897 token=android.os.BinderProxy@12e80a84 {com.justsee.googlemapapi/com.justsee.googlemapapi.MainActivity}}
04-20 12:51:18.823 11173-11173/com.justsee.googlemapapi D/ActivityThread﹕ ACT-AM_ON_RESUME_CALLED ActivityRecord{50ef897 token=android.os.BinderProxy@12e80a84 {com.justsee.googlemapapi/com.justsee.googlemapapi.MainActivity}}
04-20 12:51:18.823 11173-11173/com.justsee.googlemapapi V/ActivityThread﹕ Resume ActivityRecord{50ef897 token=android.os.BinderProxy@12e80a84 {com.justsee.googlemapapi/com.justsee.googlemapapi.MainActivity}} started activity: false, hideForNow: false, finished: false
04-20 12:51:18.823 11173-11173/com.justsee.googlemapapi V/PhoneWindow﹕ DecorView setVisiblity: visibility = 4 ,Parent =null, this =com.android.internal.policy.impl.PhoneWindow$DecorView{2618e26d I.E..... R.....ID 0,0-0,0}
04-20 12:51:18.825 11173-11173/com.justsee.googlemapapi D/ViewRootImpl﹕ hardware acceleration is enabled, this = ViewRoot{8750514 com.justsee.googlemapapi/com.justsee.googlemapapi.MainActivity,ident = 1}
04-20 12:51:18.832 11173-11173/com.justsee.googlemapapi V/ActivityThread﹕ Resuming ActivityRecord{50ef897 token=android.os.BinderProxy@12e80a84 {com.justsee.googlemapapi/com.justsee.googlemapapi.MainActivity}} with isForward=true
04-20 12:51:18.832 11173-11173/com.justsee.googlemapapi V/PhoneWindow﹕ DecorView setVisiblity: visibility = 0 ,Parent =ViewRoot{8750514 com.justsee.googlemapapi/com.justsee.googlemapapi.MainActivity,ident = 1}, this =com.android.internal.policy.impl.PhoneWindow$DecorView{2618e26d V.E..... R.....ID 0,0-0,0}
04-20 12:51:18.832 11173-11173/com.justsee.googlemapapi V/ActivityThread﹕ Scheduling idle handler for ActivityRecord{50ef897 token=android.os.BinderProxy@12e80a84 {com.justsee.googlemapapi/com.justsee.googlemapapi.MainActivity}}
04-20 12:51:18.833 11173-11173/com.justsee.googlemapapi D/ActivityThread﹕ ACT-LAUNCH_ACTIVITY handled : 0 / ActivityRecord{50ef897 token=android.os.BinderProxy@12e80a84 {com.justsee.googlemapapi/com.justsee.googlemapapi.MainActivity}}
04-20 12:51:18.852 11173-11226/com.justsee.googlemapapi D/OpenGLRenderer﹕ CanvasContext() 0x5587386310 initialize 0x55874ed5f0
04-20 12:51:18.852 11173-11226/com.justsee.googlemapapi D/Surface﹕ Surface::connect(this=0x55874ed5e0,api=1)
04-20 12:51:18.853 11173-11226/com.justsee.googlemapapi D/mali_winsys﹕ new_window_surface returns 0x3000
04-20 12:51:18.853 11173-11226/com.justsee.googlemapapi D/Surface﹕ Surface::allocateBuffers(this=0x55874ed5e0)
04-20 12:51:18.853 11173-11173/com.justsee.googlemapapi D/AbsListView﹕ onWindowFocusChanged: hasWindowFocus=true, this=maps.ei.k{204b4e4c G.ED..C. ......I. 0,0-0,0}
04-20 12:51:18.853 11173-11173/com.justsee.googlemapapi V/InputMethodManager﹕ onWindowFocus: null softInputMode=288 first=true flags=#81810100
04-20 12:51:18.853 11173-11173/com.justsee.googlemapapi V/InputMethodManager﹕ START INPUT: com.android.internal.policy.impl.PhoneWindow$DecorView{2618e26d V.E..... R.....ID 0,0-1080,1920} ic=null tba=android.view.inputmethod.EditorInfo@2a275e80 controlFlags=#104
04-20 12:51:18.860 11173-11173/com.justsee.googlemapapi I/BufferQueue﹕ [unnamed-11173-1](this:0x55875059c0,id:1,api:0,p:-1,c:-1) BufferQueue core=(11173:com.justsee.googlemapapi)
04-20 12:51:18.861 11173-11173/com.justsee.googlemapapi I/BufferQueueConsumer﹕ [unnamed-11173-1](this:0x55875059c0,id:1,api:0,p:-1,c:11173) connect(C): consumer=(11173:com.justsee.googlemapapi) controlledByApp=true
04-20 12:51:18.861 11173-11173/com.justsee.googlemapapi I/BufferQueueConsumer﹕ [unnamed-11173-1](this:0x55875059c0,id:1,api:0,p:-1,c:11173) setConsumerName: unnamed-11173-1
04-20 12:51:18.861 11173-11173/com.justsee.googlemapapi I/BufferQueueConsumer﹕ [unnamed-11173-1](this:0x55875059c0,id:1,api:0,p:-1,c:11173) setDefaultBufferSize: width=1080 height=1845
04-20 12:51:18.863 11173-12151/com.justsee.googlemapapi D/MALI﹕ eglCreateContext:206: [MALI] eglCreateContext display 0x5587179060, share context 0x0 here.
04-20 12:51:18.864 11173-11226/com.justsee.googlemapapi I/GLConsumer﹕ [unnamed-11173-1] attachToContext
04-20 12:51:18.866 11173-12151/com.justsee.googlemapapi D/MALI﹕ gles_context_new:248: Create GLES ctx 0x7f695b7018 successfully
04-20 12:51:18.866 11173-12151/com.justsee.googlemapapi D/MALI﹕ eglCreateContext:543: [MALI] eglCreateContext end. Created context 0x558738baa0 here.
04-20 12:51:18.866 11173-11226/com.justsee.googlemapapi D/Surface﹕ Surface::setBuffersDimensions(this=0x55874ed5e0,w=1080,h=1920)
04-20 12:51:18.866 11173-12151/com.justsee.googlemapapi D/Surface﹕ Surface::connect(this=0x5587411ee0,api=1)
04-20 12:51:18.867 11173-12151/com.justsee.googlemapapi I/BufferQueueProducer﹕ [unnamed-11173-1](this:0x55875059c0,id:1,api:1,p:11173,c:11173) connect(P): api=1 producer=(11173:com.justsee.googlemapapi) producerControlledByApp=true
04-20 12:51:18.867 11173-12151/com.justsee.googlemapapi D/mali_winsys﹕ new_window_surface returns 0x3000
04-20 12:51:18.868 11173-11226/com.justsee.googlemapapi D/GraphicBuffer﹕ register, handle(0x558751fa90) (w:1080 h:1920 s:1088 f:0x1 u:0x000b00)
04-20 12:51:18.942 11173-12151/com.justsee.googlemapapi D/Surface﹕ Surface::setBuffersDimensions(this=0x5587411ee0,w=1080,h=1845)
04-20 12:51:18.942 11173-12151/com.justsee.googlemapapi I/BufferQueueProducer﹕ [unnamed-11173-1](this:0x55875059c0,id:1,api:1,p:11173,c:11173) new GraphicBuffer needed
04-20 12:51:18.945 11173-12151/com.justsee.googlemapapi D/GraphicBuffer﹕ register, handle(0x55874e4fb0) (w:1080 h:1845 s:1088 f:0x2 u:0x000300)
04-20 12:51:18.955 11173-12151/com.justsee.googlemapapi D/Surface﹕ Surface::setBuffersDimensions(this=0x5587411ee0,w=1080,h=1845)
04-20 12:51:18.955 11173-12151/com.justsee.googlemapapi I/BufferQueueProducer﹕ [unnamed-11173-1](this:0x55875059c0,id:1,api:1,p:11173,c:11173) new GraphicBuffer needed
04-20 12:51:18.959 11173-12151/com.justsee.googlemapapi D/GraphicBuffer﹕ register, handle(0x55874e8ac0) (w:1080 h:1845 s:1088 f:0x2 u:0x000300)
04-20 12:51:18.962 11173-12151/com.justsee.googlemapapi I/BufferQueueProducer﹕ [unnamed-11173-1](this:0x55875059c0,id:1,api:1,p:11173,c:11173) queueBuffer: slot 0 is dropped, handle=0x55874e4fb0
04-20 12:51:19.242 11173-11226/com.justsee.googlemapapi D/Surface﹕ Surface::setBuffersDimensions(this=0x55874ed5e0,w=1080,h=1920)
04-20 12:51:19.246 11173-11226/com.justsee.googlemapapi D/GraphicBuffer﹕ register, handle(0x5587481100) (w:1080 h:1920 s:1088 f:0x1 u:0x000b00)
04-20 12:51:25.704 11173-11173/com.justsee.googlemapapi D/ViewRootImpl﹕ doProcessInputEvents ViewRoot{8750514 com.justsee.googlemapapi/com.justsee.googlemapapi.MainActivity,ident = 1}
04-20 12:51:25.704 11173-11173/com.justsee.googlemapapi D/View﹕ Touch up dispatch to maps.dg.p{4448e77 VFED..C. ........ 0,0-1080,1845}, event = MotionEvent { action=ACTION_UP, id[0]=0, x[0]=621.4246, y[0]=815.53613, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=103374561, downTime=103374481, deviceId=10, source=0x1002 }
04-20 12:51:25.930 11173-12151/com.justsee.googlemapapi D/Surface﹕ Surface::setBuffersDimensions(this=0x5587411ee0,w=1080,h=1845)
04-20 12:51:25.934 11173-12151/com.justsee.googlemapapi I/BufferQueueProducer﹕ [unnamed-11173-1](this:0x55875059c0,id:1,api:1,p:11173,c:11173) queueBuffer: fps=0.29 dur=6983.02 max=6971.79 min=11.24
04-20 12:51:25.940 11173-11226/com.justsee.googlemapapi D/Surface﹕ Surface::setBuffersDimensions(this=0x55874ed5e0,w=1080,h=1920)
04-20 12:51:25.942 11173-11226/com.justsee.googlemapapi D/GraphicBuffer﹕ register, handle(0x55874854b0) (w:1080 h:1920 s:1088 f:0x1 u:0x000b00)
答案 0 :(得分:0)
您应该实现OnMapReadyCallback接口并使用onMapReady(GoogleMap)回调方法来获取GoogleMap对象的句柄。然后,在片段上调用getMapAsync()来注册回调。请参阅下面的代码。
SELECT CONCAT('question_id: ',Q.`question_id`) AS QID,
CONCAT('answer_id: ', A.answer_id) AS AID,
CONCAT('Text: ', A.answer_text) AS Atxt
FROM `user_tests` T
INNER JOIN `test_questions` Q ON Q.`question_belongs_to` = T.`test_id`
INNER JOIN `test_answers` A ON A.`answer_belongs_to` = Q.`question_id`
WHERE T.`test_owner` = 1 #The "user id"
ORDER BY Q.`question_id`
| QID | AID | Atxt |
|----------------|--------------|-----------------------------|
| question_id: 1 | answer_id: 1 | Text: Question 1 - answer 1 |
| question_id: 1 | answer_id: 2 | Text: Question 1 - answer 2 |
| question_id: 1 | answer_id: 3 | Text: Question 1 - answer 3 |
| question_id: 2 | answer_id: 4 | Text: Question 2 - answer 1 |
| question_id: 2 | answer_id: 5 | Text: Question 2 - answer 1 |
| question_id: 3 | answer_id: 6 | Text: Question 3 - answer 1 |
| question_id: 3 | answer_id: 7 | Text: Question 3 - answer 2 |
| question_id: 3 | answer_id: 8 | Text: Question 3 - answer 3 |
| question_id: 3 | answer_id: 9 | Text: Question 3 - answer 4 |
在你的OnMapReady回调中。
GROUP BY
希望这会以某种方式帮助你
参考:https://developers.google.com/maps/documentation/android-api/map#add_a_map_to_an_android_app