Gmap.Net Marker at incorrect position but when the map is zoomed the marker goes to right place
Asked Answered
D

2

6

I've a Windows Forms Application with a Gmap.Net controller, what I want to do is to add markers based on an outside sources that provides locations. The thing is that when I add a marker is initially drawn in an incorrect location, but after I zoom out it goes to the right place. So this is what I got so far:

My Map controller is declare to be located at Panama, Panama.

private void button2_Click(object sender, EventArgs e)
{    
    //Layer count is just a variable to add new OverLays with different names
    var markersOverlay = new GMapOverlay("markers" + layerCount);

    //Marker far away in Quebec, Canada just to check my point in discussion        
    var marker = new GMarkerGoogle(new PointLatLng(58.0032, -79.4957), GMarkerGoogleType.red_small);

    markersOverlay.Markers.Add(marker);
    gmap.Overlays.Add(markersOverlay);
    layerCount++;
}

So when I press the button what I got is this (have in mind that the map location it's set to be in Panama and the marker in Canada):

First picture without zooming. Source: OC

And when I zoom out, the marker goes to the correct position in Canada.

Second picture without zooming. Source: OC

Why my marker is been drawn in Panama initially?

P.D: I already check this question but it doesn't resolve my problem because I need to be adding more than 1 marker and myMap.UpdateMarkerLocalPosition(marker) is not a solution for me.

Drugstore answered 21/7, 2015 at 16:47 Comment(3)
I got the same problem here and I'm still looking for a solution.Stribling
Hi @gm_fernandes, check the answer it worked completely, it's just a problem with the code lines order. You need to first add the Overlay to the map and then the marker to the Overlay.Drugstore
But it isn't working with my program, maybe something is missingStribling
C
11

It's because you're adding the marker to the overlay that has not been added to the map's overlays. Try to switch the order of the statements as follows:

gmap.Overlays.Add(markersOverlay);
markersOverlay.Markers.Add(marker);
Circumvent answered 22/7, 2015 at 8:33 Comment(0)
A
1

add a first marker at lat,lon = 0,0. you can also make this marker invisible with setting its marker image as 1x1 pixel transparent png image. first element of the marker do this kind of wrong placement.

Augment answered 20/2, 2017 at 7:1 Comment(1)
I recon your effort to find a workaround. If you experience the problem mentioned please try to apply the solution given. If that's not working then let's find out why. The problem was imo a problem of order of appliance.Circumvent

© 2022 - 2024 — McMap. All rights reserved.