2

i want to show the location indicator when the map is loaded and add a marker whenever the map is clicked but none of these seem to work !

protected void onCreate(Bundle savedInstanceState)  {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);


    final MapFragment mapFragment = (MapFragment) getSupportFragmentManager().findFragmentById(R.id.mapFragment);
    assert mapFragment != null;
    mapFragment.getMapAsync(new OnMapInitListener() {
        @Override
        public void onMapReady(MapView mapView) {
           OnlineManager.getInstance().enableOnlineMapStreaming(true);
            PositionManager.getInstance().startPositionUpdating();
            PositionManager.getInstance().enableRemotePositioningService();
            mpView=mapView;

            mpView.addMapGestureListener(new MapGestureAdapter() {

                @Override
                public boolean onMapClicked(final MotionEvent e, final boolean isTwoFingers) {

                    MapMarker marker = new MapMarker(new GeoCoordinates(PositionManager.getInstance().getLastKnownPosition().getLongitudeAccuracy(),PositionManager.getInstance().getLastKnownPosition().getLatitudeAccuracy()));
                    mpView.addMapObject(marker);
                    return true;
                }
            });

        }

        @Override
        public void onMapError(int error, String info) {}
    });

} 
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
  • refer this link https://stackoverflow.com/questions/17143129/add-marker-on-android-google-map-via-touch-or-tap –  Nov 14 '18 at 09:00
  • thanks but the link refers to google maps , which is irrelevant to what i have specified as map context (Sygic-mobile-sdk) – Mohamed amine Chahed Nov 14 '18 at 09:20

1 Answers1

0

You’re trying to create new Marker with getLongitudeAccuracy() and getLatitudeAccuracy(). You need to use geo coordinates!

If you want to add the marker to the position of last known gps signal you can use this code: MapMarker marker = new MapMarker(PositionManager.getInstance().getLastKnownPosition().getCoordinates())

But as there can be no known position at that time it can result in no marker added. So be sure you have location turned on and strong signal. Based on your example it would make more sense to add marker to the position you clicked on. For that purpose use this code:

        mpView.addMapGestureListener(new MapGestureAdapter() {

            @Override
            public boolean onMapClicked(final MotionEvent e, final boolean isTwoFingers) {

                MapMarker marker = new MapMarker(mpView.geoCoordinatesFromPoint(e.getX(), e.getY()));
                mpView.addMapObject(marker);
                return true;
            }
        });
bio007
  • 893
  • 11
  • 20