2016-07-20 8 views
0

私は自分のアプリでGoogleマップを使用しています。方法onMapReadyには緯度と経度が組み込まれています。私の質問は、私がメソッド内でこれらの座標を変更できるかどうかです。 私がやろうとしていることは私の活動の中で私は座標を使って放送受信機を得ています。メソッドonMapReady でこれらの座標を更新したいので、現在の位置が表示されます。gps座標をonMapReadyに更新するには?

GPSアクティビティ

public class GPS extends FragmentActivity implements OnMapReadyCallback , Listen { 

    private Button startGPS,stopGPS; 
    private TextView addresTv; 
    private GoogleMap mMap; 
    private GPSTurnOnOff gpsTurnOnOff; 
    private IntentFilter mIntent; 
    private BroadcastReceiver GPSBroadcast; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_gps); 
    // 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); 

    mIntent = new IntentFilter("BroadcastGPS"); 

      GPSBroadcast = new BroadcastReceiver() { 
     @Override 
     public void onReceive(Context context, Intent intent) { 
      String latitude = intent.getStringExtra("LATITUDE"); 
      String longitude = intent.getStringExtra("LONGITUE"); 
     } 
    }; 
    } 

     /** 
* 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 sydney = new LatLng(-34, 151); 
    mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney")); 
    mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney)); 
} 

私はこのライン緯度経度シドニー=新しい緯度経度(-34、151)に入力することができる方法。放送から受信した新しい座標

答えて

0

使用すると、あなたが** **プライベートGoogleマップGoogleマップを意味して、グローバルオブジェクトとしてonReceiveにそれを使用するグローバルMMAP(Googleマップ)オブジェクト

GPSBroadcast = new BroadcastReceiver() { 
    @Override 
    public void onReceive(Context context, Intent intent) { 
     String latitude = intent.getStringExtra("LATITUDE"); 
     String longitude = intent.getStringExtra("LONGITUE"); 
     if(mMap != null){ 
      // Do what you want here 
      // mMap.addMarker(...); 
      // mMap.moveCamera(...); 
     } 
    } 
} 
+0

を使用することができますか? –

+0

はい、ご覧のとおり、とてもクリアです – Blackkara