2016-11-22 12 views
0

Я хочу показать простой адрес на картах. Я следил за всеми шагами, создавал MapsActivity, создавал Fragment ... , но результат остается тем же, я получаю глобальную карту без какого-либо маркера любого адреса (см. Вложение).addMarker не работает. показать адрес в андроидных фрагментах карты

the result- screenShot

and here my code : 

    import android.support.v4.app.FragmentActivity; 
import android.os.Bundle; 

import com.google.android.gms.maps.CameraUpdateFactory; 
import com.google.android.gms.maps.GoogleMap; 
import com.google.android.gms.maps.OnMapReadyCallback; 
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.MarkerOptions; 

import static oukarroum.myapplication2.R.drawable.marker; 

public class MapsActivity extends FragmentActivity implements OnMapReadyCallback { 

    private GoogleMap mMap; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_maps2); 
     // Obtain the SupportMapFragment and get notified when the map is ready to be used. 
     SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager() 
       .findFragmentById(R.id.map); 

     mapFragment.getMapAsync(this); 
    } 


    /** 
    * Manipulates the map once available. 
    * This callback is triggered when the map is ready to be used. 
    * This is where we can add markers or lines, add listeners or move the camera. In this case, 
    * we just add a marker near Sydney, Australia. 
    * If Google Play services is not installed on the device, the user will be prompted to install 
    * it inside the SupportMapFragment. This method will only be triggered once the user has 
    * installed Google Play services and returned to the app. 
    */ 
    @Override 
    public void onMapReady(GoogleMap googleMap) { 
     mMap = googleMap; 

     // Add a marker in Sydney and move the camera 
     mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(
       new LatLng(44.797283, 20.460663), 12)); 

      mMap.addMarker(new MarkerOptions() 
        .position(new LatLng(44.797283, 20.460663)) 
        .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE))); 

    } 


} 


my acitvity_Maps.xml : 



<fragment xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:map="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/map" 
    android:name="com.google.android.gms.maps.SupportMapFragment" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context="oukarroum.myapplication2.MapsActivity" /> 



my androidManifest.xml : 



<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
package="xxxx.myapplication2"> 

<!-- 
     The ACCESS_COARSE/FINE_LOCATION permissions are not required to use 
     Google Maps Android API v2, but you must specify either coarse or fine 
     location permissions for the 'MyLocation' functionality. 
    --> 

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> 


<application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" 
    android:supportsRtl="true" android:theme="@style/AppTheme"> 
    <activity android:name=".MainActivity"> 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 

      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
    </activity> 
    <!-- 
ATTENTION: This was auto-generated to add Google Play services to your project for 
    App Indexing. See https://g.co/AppIndexing/AndroidStudio for more information. 
     --> 
    <activity android:name=".CustomersList"> 
     <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" /> 
    <!-- 
      The API key for Google Maps-based APIs is defined as a string resource. 
      (See the file "res/values/google_maps_api.xml"). 
      Note that the API key is linked to the encryption key used to sign the APK. 
      You need a different API key for each encryption key, including the release key that is used to 
      sign the APK for publishing. 
      You can define the keys for the debug and release targets in src/debug/ and src/release/. 
     --> 
    <meta-data android:name="com.google.android.geo.API_KEY" android:value="AIzaSyAxxxxxx /> 

    <activity android:name=".MapsActivity" 
     android:label="@string/title_activity_maps"> 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 

      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 

    </activity> 
    <uses-library android:name="com.google.android.maps" /> 
    <uses-feature android:glEsVersion="0x00020000" android:required="true" /> 

</application> 

</manifest> 


    [1]: https://i.stack.imgur.com/eQdwN.png 
+0

загрузить https://github.com/googlemaps/android-samples, здесь вы можете найти все обновленные материалы, которые вы хотите связать с googlemapapiv2. – Radhey

+0

Привет, momo, это «метаданные android: name =» com.google.android.geo.API_KEY «android: value =« AIzaSyAxxxxxx /> », что у вашего фактического кода есть или вы скрыли значение для сообщения? –

+0

любая идея? я все еще заблокирован – momo

ответ

0

Это когда-то случилось со мной также, я должен был спросить у пользователя разрешения, потому что я использовал андроида M, чтобы проверить. проверьте, является ли это вашим случаем.

@TargetApi(Build.VERSION_CODES.M) 
@Override 
public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) { 
    switch (requestCode) { 
     case MY_PERMISSIONS_REQUEST_FINE_LOCATION: { 
      if (grantResults[0] == PackageManager.PERMISSION_GRANTED) { 
       requestPermissions(new String[]{Manifest.permission.ACCESS_FINE_LOCATION},MY_PERMISSIONS_REQUEST_FINE_LOCATION); 
      } else { 
       Toast.makeText(getContext(), "Permission denied", Toast.LENGTH_SHORT).show(); 
      } 
      return; 
     }} 
+0

благодарю вас за ответ, это уже сделано, здесь я поставил XXXXX, чтобы не показывать свой ключ публике. – momo

+0

какая версия api вы используете? Android –