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

我正在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,但是我可以看到,如果我不传递纬度/经度值。


潇潇雨雨
浏览 507回答 4
4回答

波斯汪

我不知道您是否已修复代码,现在还可以,但是在 onCreate()if (getIntent().getExtras() != null) {   final Bundle bundle = getIntent().getBundleExtra("LOCATION");   mLatitude = bundle.getDouble("LATITUDE");   mLatitude = bundle.getDouble("LONGITUDE");}第二个mLatitude我认为它必须mLongitude就像您在下一行中调用它一样。抱歉,我迟到了,没用。

幕布斯6054654

第一个craete方法setupDestationLocation&nbsp;public void setupDestationLocation(double longlat, double latitue, String title) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; LatLng Shop = new LatLng(longlat, latitue);&nbsp; &nbsp;/* if (DestinationMarker != null) {&nbsp; &nbsp; &nbsp; DestinationMarker.remove();&nbsp; &nbsp; }*/&nbsp; &nbsp; DestinationMarker = mMap.addMarker(new MarkerOptions()&nbsp; &nbsp; &nbsp; .position(Shop)&nbsp; &nbsp; &nbsp; .title(market_n)&nbsp; &nbsp; &nbsp; .title(title)&nbsp; &nbsp; &nbsp; .icon(BitmapDescriptorFactory.fromResource(R.mipmap.ic_marker_shop)));&nbsp; &nbsp; CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(Shop, 14);&nbsp; &nbsp; mMap.animateCamera(cameraUpdate);&nbsp; }现在,只需在方法(onMapReady)中调用方法String title = "market";&nbsp; &nbsp; for(int i = 0 ; i < 8 ; i++ ) {&nbsp; &nbsp; &nbsp; double offset = i / 08d;&nbsp; &nbsp; &nbsp; setupDestationLocation(longlat+offset,latitue,title+i);&nbsp; &nbsp; }
打开App,查看更多内容
随时随地看视频慕课网APP