标记未显示在我的地图上。我在onMapReady类中编写了代码,但是似乎没有人可以帮助我。我不知道问题所在。我尝试了很多次。
public class Home extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener, OnMapReadyCallback,
GoogleApiClient.ConnectionCallbacks,
GoogleApiClient.OnConnectionFailedListener,
LocationListener{
private GoogleMap mMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.addDrawerListener(toggle);
toggle.syncState();
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
//Map
mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
//Add Marker
LatLng kilin = new LatLng(33.6518, 73.1566);
mMap.addMarker(new MarkerOptions().position(kilin).title("Stop")).setIcon(BitmapDescriptorFactory.fromResource(R.drawable.car));
}
}
答案 0 :(得分:0)
您的代码应该可以正常工作,请确保图标不要太小或太透明或有其他东西,添加标记后请致电mMap.moveCamera(CameraUpdateFactory.newLatLng(kilin));
以确保您在正确的位置查找它