标记图像未显示在地图中

问题描述 投票:-1回答:3
@Override
public void onLocationChanged(Location location)
{
    mLastLocation = location;
    if (mCurrLocationMarker != null) {
        mCurrLocationMarker.remove();
    }
    LatLng latLng = new LatLng(location.getLatitude(), location.getLongitude());
    BitmapDescriptor markLocation = BitmapDescriptorFactory.fromResource(R.drawable.abc);
    MarkerOptions markerOptions = new MarkerOptions();
    markerOptions.position(latLng);
    markerOptions.title("Current Position");
    markerOptions.icon(markLocation);
    markerOptions.draggable(true);
    mMap.addMarker(markerOptions);
    mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng,11));
}

图像保存在可绘制文件夹中,但当map中的当前位置时不显示图像。

android google-maps
3个回答
0
投票

嗨根据我的理解,你可以像这种格式显示标记

 @Override
public void onMapReady(GoogleMap googleMap) {
    mMap = googleMap;


    CameraPosition cameraPosition = new CameraPosition.Builder()
            .target(new LatLng(Double.parseDouble(latitude), Double.parseDouble(longitude)))     // Sets the center of the map to Mountain View
            .zoom(17)                   // Sets the zoom
            .bearing(90)                // Sets the orientation of the camera to east
            .tilt(30)                   // Sets the tilt of the camera to 30 degrees
            .build();                   // Creates a CameraPosition from the builder
    mMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
    mMap.addMarker(new MarkerOptions()
            .position(new LatLng(Double.parseDouble(latitude), Double.parseDouble(longitude)))
            .title(location_name)
            .icon(BitmapDescriptorFactory.fromResource(R.drawable.big_marker)));

}


0
投票

使用InvokeIcon()在地图上显示标记图标,看看:

@Override
public void onLocationChanged(Location location)
{
    mLastLocation = location;
    if (mCurrLocationMarker != null) {
        mCurrLocationMarker.remove();
    }
    LatLng latLng = new LatLng(location.getLatitude(), location.getLongitude());
    BitmapDescriptor markLocation = BitmapDescriptorFactory.fromResource(R.drawable.abc);
    MarkerOptions markerOptions = new MarkerOptions();
    markerOptions.position(latLng);
    markerOptions.title("Current Position");
    markerOptions.draggable(true);
    mMap.addMarker(markerOptions);
    markerOptions.InvokeIcon(markLocation);
    mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng,11));
}

0
投票

添加此行以加载Marker-:

mMap.addMarker(new MarkerOptions()
            .position(new LatLng(Double.parseDouble(latitude), Double.parseDouble(longitude)))
            .title("India")
            .icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_launcher)));
© www.soinside.com 2019 - 2024. All rights reserved.