我已经实现了一个导航抽屉,其菜单是片段。我已经在家庭片段中推出了地图并且它确实出现但是标记不是。这里是标记的代码,它不会显示在应用程序的任何位置。 地图活动:
public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {
GoogleMap mMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
// 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);
}
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
LatLng muze = new LatLng(41.326382, 19.821458);
mMap.addMarker(new MarkerOptions().position(muze).title("National Museum of Tirana"));
LatLng liqen = new LatLng(41.326382, 19.821458);
mMap.addMarker(new MarkerOptions().position(liqen).title("Artifical Lake of Tirana"));
LatLng monument = new LatLng(41.320155, 19.786377);
mMap.addMarker(new MarkerOptions().position(monument).title("Skanderbeg STatue"));
LatLng teater = new LatLng(41.321693, 19.817442);
mMap.addMarker(new MarkerOptions().position(teater).title("National Theatre"));
mMap.moveCamera(CameraUpdateFactory.newLatLng(muze));
LatLng TiranaCenter = new LatLng(41.327541, 19.818609);
mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(TiranaCenter,15.0f));
mMap.setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener() {
@Override
public void onInfoWindowClick(Marker m) {
Intent intent1 = new Intent(getApplicationContext(),marker.class);
String title = m.getTitle();
intent1.putExtra("title",title);
startActivity(intent1);
}
});
}
}
marker.java
package com.example.user.appsightseeing;
/**
* Created by User on 20/06/2017.
*/
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.TextView;
import static com.example.user.appsightseeing.R.layout.activity_maps;
public class marker extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(activity_maps);
String cinema_id =getIntent().getStringExtra("title");
TextView text = (TextView)findViewById(R.id.emri);
text.setText(cinema_id);
}
}
答案 0 :(得分:0)
在代码中查看此功能。
@Override
public void onMarkerDragEnd(Marker marker) {
Toast.makeText(
MainActivity.this,
"Lat " + map.getMyLocation().getLatitude() + " "
+ "Long " + map.getMyLocation().getLongitude(),
Toast.LENGTH_LONG).show();
System.out.println("yalla b2a "
+ map.getMyLocation().getLatitude());
}