代码之家  ›  专栏  ›  技术社区  ›  Shahad R.

标记未显示在HERE地图上

  •  1
  • Shahad R.  · 技术社区  · 9 年前

    我想在地图上显示一个标记,但它没有显示,这是我使用的代码, 我正在使用Android的HERE Map SDK

    Image img = new Image();
                    try {
                        img.setImageResource(R.drawable.marker);
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                    MapMarker mm = new MapMarker();
                    mm.setIcon(img);
                    mm.setCoordinate(new GeoCoordinate(21.609512, 39.131269));
    
    1 回复  |  直到 9 年前
        1
  •  3
  •   Marco    9 年前

    创建MapMarker后,您还需要通过map.addMapObject(…)将其添加到地图中

    请参阅我的示例(其中mMap是我的Map实例,锚点位于底部而不是中心):

        private void addMarker(GeoCoordinate geoCoordinate) 
        {
            if (mMarker == null) {
                Image image = new Image();
                try {
                    image.setImageResource(R.drawable.pin);
                } catch (final IOException e) {
                    e.printStackTrace();
                }
                mMarker = new MapMarker(geoCoordinate, image);
                mMarker.setAnchorPoint(new PointF(image.getWidth()/2, image.getHeight()));
                mMap.addMapObject(mMarker);
            } else {
                mMarker.setCoordinate(geoCoordinate);
            }
            mMap.setCenter(geoCoordinate, Animation.BOW);
        }