Autore Topic: Problemi Marker che non ci sono/non si vedono  (Letto 396 volte)

Offline Macca

  • Nuovo arrivato
  • *
  • Post: 9
  • Respect: 0
    • Mostra profilo
  • Dispositivo Android:
    Samsung galaxy s4 mini
  • Sistema operativo:
    Windows 8
Problemi Marker che non ci sono/non si vedono
« il: 05 Novembre 2014, 16:32:32 CET »
0
Ragazzi sto riscontrando qualche problema con i marker di Google map, le sto provando tutte, ma niente... vi posto il codice se vi va di darci un'occhiata:

Main:
Codice (Java): [Seleziona]
public class MainActivity extends FragmentActivity
{
        GoogleMap map;
        final LatLng STARTING_POINT = new LatLng(45.4640704, 9.1719064); // Milano

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        MapFragment mMapFragment = MapFragment.newInstance(mapOptions());
        FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
        fragmentTransaction.add(R.id.map, mMapFragment);
        fragmentTransaction.commit();
        setUpMapIfNeeded();
       
       
       
        Marker m = map.addMarker(new MarkerOptions()
        .position(STARTING_POINT)
        .title("Hello world")
        .visible(true));
        m.showInfoWindow();
        map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
        map.addMarker(new MarkerOptions()
                .position(new LatLng(10, 10))
                .title("Hello world"));
       
        map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map))
                .getMap();
           
            if (map!=null){
              Marker hamburg = map.addMarker(new MarkerOptions().position(STARTING_POINT)
                  .title("Hamburg"));
              Marker kiel = map.addMarker(new MarkerOptions()
                  .position(STARTING_POINT)
                  .title("Kiel")
                  .snippet("Kiel is cool")
                  .icon(BitmapDescriptorFactory
                      .fromResource(R.drawable.ic_launcher)));
              }
    }
   
   
   
   
   
    private GoogleMapOptions mapOptions()
    {
        GoogleMapOptions options = new GoogleMapOptions();

        options.mapType(GoogleMap.MAP_TYPE_HYBRID)
        .compassEnabled(true)
        .rotateGesturesEnabled(true)
        .scrollGesturesEnabled(true)
        .tiltGesturesEnabled(true)
        .zoomGesturesEnabled(true)
        .zoomControlsEnabled(true);

        CameraPosition cameraPosition = new CameraPosition.Builder()
        .target(STARTING_POINT)
        .zoom((float) 14)
        .build();

        options.camera(cameraPosition);
        return options;
    }
    private void setUpMapIfNeeded()
    {
        // Do a null check to confirm that we have not already instantiated the map.
        if (map == null)
        {
            map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();

            // Check if we were successful in obtaining the map.
            if (map != null)
            {
                // The Map is verified. It is now safe to manipulate the map.
                map.addMarker(new MarkerOptions()
                .position(STARTING_POINT)
                .title("Hello world")
                .visible(true));
            }
        }
    }
}



Layout:
Codice (XML): [Seleziona]
<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
         android:id="@+id/map"
         android:layout_width="match_parent"
         android:layout_height="match_parent"
         android:name="com.google.android.gms.maps.MapFragment"/>


Manifest:
Codice (XML): [Seleziona]
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
   package="com.example.mappefinale"
   android:versionCode="1"
   android:versionName="1.0" >
    <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"/>
<!-- 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"/>

    <uses-sdk
       android:minSdkVersion="12"
       android:targetSdkVersion="21" />

    <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.gms.version"
   android:value="@integer/google_play_services_version" />
        <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.maps.v2.API_KEY"
   android:value="AIzaSyCUz-zpe_lGbJg_g9bGC6mL6vsLTQ9Kcbo"/>
    </application>

</manifest>

Come vedete i marker ho provato a metterli un pò in ogni modo, ma niente, grazie in anticipo!

Offline eagledeveloper

  • Translate Team
  • Utente senior
  • ****
  • Post: 516
  • Respect: +37
    • Google+
    • 347516210
    • dark_pinz
    • @WandDStudios
    • Mostra profilo
    • W&D Studios
  • Dispositivo Android:
    HTC One X e HTC One
  • Play Store ID:
    W%26D+Studios
  • Sistema operativo:
    Ubuntu / Windows 7
Re:Problemi Marker che non ci sono/non si vedono
« Risposta #1 il: 06 Novembre 2014, 11:17:39 CET »
0
Penso che il problema sia qui:

Codice (Java): [Seleziona]
MapFragment mMapFragment = MapFragment.newInstance(mapOptions());
FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
fragmentTransaction.add(R.id.map, mMapFragment);
fragmentTransaction.commit();

Sostituisci la tua mappa con un altra instanza della mappa. Ma i maker vai a metterli nell'istanza precedente e quindi non si vedono.
I numeri contano molto di più del seme.