【发布时间】:2017-09-09 09:26:35
【问题描述】:
我正在尝试为导航抽屉中列出的每个项目提供位置坐标,并将其指向谷歌地图。
它如何获取我分配给 onNavigationItemSelected() 中的变量到 onMapReady() 的 lat 和 long?
//This is were I assign the coordiantes
@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
int id = item.getItemId();
double lat = 0;
double lon = 0;
if (id == R.id.redBuilding){
/*lat = 13.010982;
lon = 80.235444;
String latitude = Double.toString(lat);
String longitude = Double.toString(lon);
latLong = latitude+"/"+longitude; */
}
if (id == R.id.nav_share) {
} else if (id == R.id.nav_send) {
}
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
}
我想在此方法中获取分配的坐标以将其指向地图:
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
LatLng latLon = new LatLng(13.0827, 80.2707);
mMap.addMarker(new MarkerOptions().position(latLon).title("Marker is in Chennai.").snippet("India"));
mMap.moveCamera(CameraUpdateFactory.newLatLng(latLon));
}
我只使用一个活动,其中地图位于片段中。
【问题讨论】:
-
方法
onMapReady(GoogleMap googleMap)是否在片段中? -
您是否在不同的片段中加载地图?或者在activity中加载地图片段
-
@SifatOshan,没有。
-
@tahsinRupam,我正在将地图加载到我在主要活动本身中显示的片段中。
-
您可以使用接口将LatLng值发送到片段并更新地图
标签: java android google-maps android-studio