【发布时间】:2014-12-31 10:10:57
【问题描述】:
我按照教程中的
https://developers.google.com/maps/documentation/android/start
我设法将地图加载到我的应用程序中。现在我想使用纬度和经度在我的应用程序中添加一些标记。我该怎么做?我尝试了一些东西,但没有奏效。我试过的代码如下。
我打算这样做。但是我得到一个空点异常。这是什么原因?
GoogleMap googleMap = null;
MapFragment fm = (MapFragment) (activity.getFragmentManager())
.findFragmentById(R.id.map);
googleMap = fm.getMap();
double latitude = 7.421226;
double longitude =80.401264 ;
// create marker
MarkerOptions marker = new MarkerOptions().position(new LatLng(latitude, longitude)).title("Hello Maps ");
// adding marker
googleMap.addMarker(marker);
我的布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="@+id/filmhall"
android:background="@color/grey" >
<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.google.android.gms.maps.SupportMapFragment"/>
</LinearLayout>
【问题讨论】:
-
有任何 logcat 错误
标签: android google-maps marker