我在我的应用上使用谷歌地图。方法onMapReady
建立了经度和经度。我的问题是我是否可以在方法中更改这些坐标。
我想要做的就是在我的活动中,我得到了带坐标的广播接收器。然后我想在方法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));
}
我怎样才能进入这一行 LatLng sydney = new LatLng(-34,151); 从广播收到的新坐标
答案 0 :(得分:0)
使用可以使用全局mMap(GoogleMap)对象
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(...);
}
}
}