2016-07-20 8 views
0

Ich verwende Google Maps in meiner App. Die Methode onMapReady hat Längen- und Breitengrad. Meine Frage ist, ob ich diese Koordinaten in der Methode ändern kann. Was ich versuche zu tun ist in meiner Tätigkeit Ich bekomme Rundfunkempfänger mit den Koordinaten. dann möchte ich diese Koordinaten in der Methode onMapReady aktualisieren, damit es mir den gegenwärtigen Standort zeigt.Wie aktualisiert man GPS-Koordinaten onMapReady?

GPS Aktivität

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)); 
} 

wie kann ich auf diese Linie LatLng sydney = new LatLng (-34, 151) eingeben; die neuen Koordinaten, die von der Sendung empfangen

Antwort

0

Verwendung global MMAP (GoogleMap) Objekt

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

Sie bedeuten ** Privat GoogleMap googleMap ** und dann verwenden Sie es auf OnReceive als globales Objekt verwenden kann? –

+0

ja, wie Sie sehen, so klar – Blackkara