java Android |将导航抽屉添加到默认地图活动
我已经寻找这个问题的答案好几个星期了,所以如果我看起来有点沮丧,请原谅。因为我是
事先,如果之前有人问过这个问题,我很抱歉。我不熟悉Android编程(我主要做网络应用),这对我来说是一个全新的世界。感谢您的帮助
我想做的是将导航抽屉添加到标准的常规地图活动中。我该怎么做呢?我希望每个按钮都能将地图重新居中到另一个地方
当我们在做的时候,我计划在我的地图上创建一个KML图层。正如你所知,KML积分中内置了信息,因此当你点击/点击它们时,你可以看到信息。我想让KML point打开带有内置信息的导航抽屉。我可以使用默认的安卓点数来实现这一点,但KML的一些功能是值得赞赏的。如果您想要一个参考框架,可以考虑以下JavaScript示例,但侧栏大部分时间是隐藏的:https://developers.google.com/maps/documentation/javascript/kml
主要活动。java:
package us.tourismproject.jared.tourismproject安卓;
import 安卓.content.res.Resources;
import 安卓.nfc.Tag;
import 安卓.support.v4.app.FragmentActivity;
import 安卓.os.Bundle;
import 安卓.support.v7.app.AppCompatActivity;
import 安卓.util.Log;
import com.google.安卓.gms.maps.CameraUpdateFactory;
import com.google.安卓.gms.maps.GoogleMap;
import com.google.安卓.gms.maps.OnMapReadyCallback;
import com.google.安卓.gms.maps.SupportMapFragment;
import com.google.安卓.gms.maps.model.LatLng;
import com.google.安卓.gms.maps.model.MapStyleOptions;
import com.google.安卓.gms.maps.model.MarkerOptions;
public class MainActivity extends AppCompatActivity implements OnMapReadyCallback {
private static final String TAG = MainActivity.class.getSimpleName();
private GoogleMap mMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// 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);
}
/**
* 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;
try {
// Customise the styling of the base map using a JSON object defined
// in a raw resource file.
boolean success = googleMap.setMapStyle(
MapStyleOptions.loadRawResourceStyle(
this, R.raw.style_json));
if (!success) {
Log.e(TAG, "Style parsing failed.");
}
} catch (Resources.NotFoundException e) {
Log.e(TAG, "Can't find style. Error: ", e);
}
// Position the map's camera near Sydney, Australia.
googleMap.moveCamera(CameraUpdateFactory.newLatLng(new LatLng(-34, 151)));
}
}
主要活动。xml
<fragment xmlns:安卓="http://schemas.安卓.com/apk/res/安卓"
xmlns:map="http://schemas.安卓.com/apk/res-auto"
xmlns:tools="http://schemas.安卓.com/tools"
安卓:id="@+id/map"
安卓:name="com.google.安卓.gms.maps.SupportMapFragment"
安卓:layout_width="match_parent"
安卓:layout_height="match_parent"
tools:context="us.tourismproject.jared.tourismproject安卓.MainActivity" />
提前谢谢你的帮助。你好
# 1 楼答案
如果您想在地图活动上方导航,请更新活动\u main。xml
它将创建您的导航抽屉正如rajan提到的一个答案,您需要编写一些代码来处理导航抽屉