标记图像未显示在地图中

时间:2018-01-05 05:34:46

标签: android google-maps

@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中的当前位置时,图像不会显示。

3 个答案:

答案 0 :(得分: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)));

}

答案 1 :(得分: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));
}

答案 2 :(得分:0)

添加此行以加载标记 - :

mMap.addMarker(new MarkerOptions()
            .position(new LatLng(Double.parseDouble(latitude), Double.parseDouble(longitude)))
            .title("India")
            .icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_launcher)));