为了账号安全,请及时绑定邮箱和手机立即绑定

如何在Google Map API v2中的MapFragment上显示多个标记?

如何在Google Map API v2中的MapFragment上显示多个标记?

潇潇雨雨 2019-12-27 14:59:07
我正在Google Map API v2应用程序中显示地图。我已经按照所有步骤操作,要在我的应用程序中启用Google Map。public class PinLocationOnMapView extends FragmentActivity {    private double mLatitude = 0.0, mLongitude = 0.0;    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        SupportMapFragment fragment = SupportMapFragment.newInstance();        getSupportFragmentManager().beginTransaction()                .add(android.R.id.content, fragment).commit();    }}如果使用此代码,它将向我显示地图,但是如果提供纬度/经度值,则不会加载地图图块,并且只能看到白色图块。以下是上述类的onCreate()中编写的代码: if (getIntent().getExtras() != null) {            final Bundle bundle = getIntent().getBundleExtra("LOCATION");            mLatitude = bundle.getDouble("LATITUDE");            mLongitude = bundle.getDouble("LONGITUDE");        } else {            finish();        }        GoogleMapOptions options = new GoogleMapOptions();        LatLng latLng = new LatLng(mLatitude, mLongitude);        CameraPosition cameraPosition;// = new CameraPosition(latLng, 0, 0, 0);        cameraPosition = CameraPosition.fromLatLngZoom(latLng, (float) 14.0);        options.mapType(GoogleMap.MAP_TYPE_SATELLITE).camera(cameraPosition)                .zoomControlsEnabled(true).zoomGesturesEnabled(true);        SupportMapFragment fragment = SupportMapFragment.newInstance(options);        getSupportFragmentManager().beginTransaction()                .add(android.R.id.content, fragment).commit(); 另外,我有一个经度/纬度值列表。我想在上面显示它们MapFragment,如何在上面显示多个标记MapFragment?我尝试了MapView和ItemizedOverlay,但对我没有用。我相信我已经正确创建了SHA1要获取API密钥的密钥,因为如果那是错误的,我也看不到map的使用MapFragment,但是我可以看到,如果我不传递纬度/经度值。
查看完整描述

4 回答

?
波斯汪

TA贡献1811条经验 获得超4个赞

我不知道您是否已修复代码,现在还可以,但是在 onCreate()


if (getIntent().getExtras() != null) {

   final Bundle bundle = getIntent().getBundleExtra("LOCATION");

   mLatitude = bundle.getDouble("LATITUDE");

   mLatitude = bundle.getDouble("LONGITUDE");

}

第二个mLatitude我认为它必须mLongitude就像您在下一行中调用它一样。


抱歉,我迟到了,没用。


查看完整回答
反对 回复 2019-12-27
?
幕布斯6054654

TA贡献1876条经验 获得超7个赞

第一个craete方法setupDestationLocation


 public void setupDestationLocation(double longlat, double latitue, String title) {

          LatLng Shop = new LatLng(longlat, latitue);

   /* if (DestinationMarker != null) {

      DestinationMarker.remove();

    }*/

    DestinationMarker = mMap.addMarker(new MarkerOptions()

      .position(Shop)

      .title(market_n)

      .title(title)

      .icon(BitmapDescriptorFactory.fromResource(R.mipmap.ic_marker_shop)));

    CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(Shop, 14);

    mMap.animateCamera(cameraUpdate);


  }

现在,只需在方法(onMapReady)中调用方法


String title = "market";

    for(int i = 0 ; i < 8 ; i++ ) {

      double offset = i / 08d;


      setupDestationLocation(longlat+offset,latitue,title+i);

    }


查看完整回答
反对 回复 2019-12-27
  • 4 回答
  • 0 关注
  • 505 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信