Bonjour,
ça fais un long moment que j'essaye une app qui utilise la géolocalisation, mais j'y arrive pas, soit ma carte apparait en fragement soit l'application s'arrête car il y a un bug, pourtant j'ai test à partir d'un tuto mais rien n'y fais.
Voici la démarche que j'ai effectué :
- j'ai bien générer ma clé API
voici mon android manifest:
voici mon fichier activity_main.xml:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52 <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="ca.sfu.cmpt276.bfraser" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="11" android:targetSdkVersion="17" /> <permission android:name="ca.sfu.cmpt276.bfraser.permission.MAPS_RECEIVE" android:protectionLevel="signature"/> <uses-permission android:name="ca.sfu.cmpt276.bfraser.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.WRITE_EXTERNAL_STORAGE"/> <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/> <!-- The following two permissions are not required to use Google Maps Android API v2, but are recommended. --> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> <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" > <meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="AIzaSyAsa9GP-QX6wYzcxHAdPonRge67VDDotWk"/> <activity android:name="ca.sfu.cmpt276.bfraser.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> </application> </manifest>
et voici mon code java:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49 <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" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context=".MainActivity" > <Button android:id="@+id/btnSurrey" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_alignParentTop="true" android:onClick="onClick_Surrey" android:text="Surrey" /> <fragment android:id="@+id/map" android:name="com.google.android.gms.maps.MapFragment" android:layout_below="@+id/btnSurrey" android:layout_width="match_parent" android:layout_height="match_parent" /> <Button android:id="@+id/btnBurnaby" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:onClick="onClick_Burnaby" android:text="Burnaby" /> <Button android:id="@+id/btnCity" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:onClick="onClick_City" android:text="City" /> </RelativeLayout>
J'ai également bien importé la library googleplayservice pour utiliser la map, mais parfois j'ai l'erreur " android manifest does not have the right value, j'ai vu que c'etait parce que j'avais une ancienne version de googleplayservice, et ils disent de rajouter :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46 //tous mes imports public class MainActivity extends Activity { private final LatLng LOCATION_BURNABY = new LatLng(49.27645, -122.917587); private final LatLng LOCATION_SURRREY = new LatLng(49.187500, -122.849000); private GoogleMap map; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap(); map.addMarker(new MarkerOptions().position(LOCATION_SURRREY).title("Find me here!")); } @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; } public void onClick_City(View v) { // CameraUpdate update = CameraUpdateFactory.newLatLng(LOCATION_BURNABY); map.setMapType(GoogleMap.MAP_TYPE_SATELLITE); CameraUpdate update = CameraUpdateFactory.newLatLngZoom(LOCATION_BURNABY, 9); map.animateCamera(update); } public void onClick_Burnaby(View v) { map.setMapType(GoogleMap.MAP_TYPE_TERRAIN); CameraUpdate update = CameraUpdateFactory.newLatLngZoom(LOCATION_BURNABY, 14); map.animateCamera(update); } public void onClick_Surrey(View v) { map.setMapType(GoogleMap.MAP_TYPE_NORMAL); CameraUpdate update = CameraUpdateFactory.newLatLngZoom(LOCATION_SURRREY, 16); map.animateCamera(update); } }
j'ai donc penser qu'il fallait rajouter la balise meta data dans le manifest de googleplayservice mais je sais pas trop si c'est exact ?
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4 <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
Un grand merci pour votre aide
Partager