2016-11-18 11 views
0

Googleマップにダイナミックマーカーを作成しようとしていますが、地図が読み込まれていません。地図のアクティビティは読み込まれますが、マーカーは作成されません。地図にダイナミックマーカーを追加する

import android.support.v4.content.ContextCompat; 
    import android.support.v4.app.FragmentActivity; 
    import android.os.Bundle; 
    import android.widget.Toast; 
    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.CameraPosition; 
    import com.google.android.gms.maps.model.LatLng; 
    import com.google.android.gms.maps.model.MarkerOptions; 
    import android.content.pm.PackageManager; 





public class Mapa extends FragmentActivity implements OnMapReadyCallback { 

private GoogleMap mMap; 
public double posx; 
public double posy; 
public String desc; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_mapa); 

    SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager() 
      .findFragmentById(R.id.map); 
    mapFragment.getMapAsync(this); 

    //SupportMapFragment googleMap=(SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map); 

    Bundle b = getIntent().getExtras(); 
    posx= b.getDouble("PosicionX"); 
    posy= b.getDouble("PosicionY"); 
    desc = b.getString("Descripcion"); 


} 


/** 
* 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 
    LatLng lugar = new LatLng(posx, posy); 
    mMap.addMarker(new MarkerOptions().position(lugar).title(desc)); 
    mMap.moveCamera(CameraUpdateFactory.newLatLng(lugar)); 
} 
} 

イム2倍と1つの文字列を送信し、前activtyからの送信情報を受信するバンドルを使用して: はここのコードです。なんらかの理由で、私は自分の携帯電話でそれを実行するときにmaps_activityを開きますが、マーカーを作成しません。 xmlコード全体を貼り付けることはありませんが、マップオブジェクトの名前は「マップ」

+0

たぶんあなたは緯度と経度を交換しています...あなたは 'LatLng lugar = new LatLng(posy、posx);をやってみましたか? – antonio

+0

補間の緯度と経度に名前をつけて、順序を混乱させないようにしてください –

+0

また 'LatLng'は' Parcelable'を実装しているので、 'putParcelable'を介して' Bundle'に直接追加でき、 'getParcelable'を使って取り出すことができます – antonio

答えて

0

コードはうまくいきました。問題は、以前のバージョンのAndroid用で開発していたAndroidのバージョンでした私は自分の携帯電話に持っている、何らかの理由でそれはちょうどGoogleマップを正しく開いていないだろう、したがって私は私の携帯電話で持っているのと同じアンドロイドバージョンに穴のアプリをリメイクしなければならなかった。

関連する問題