Google Map marker w/ custom icon

Answered
0
0

Hi, I’m trying to use the GoogleMap.AddMarker method to use a custom marker icon.  I’m having trouble figuring out the syntax for the 3rd parameter, which is the MarkerOptions object specification…  Can you help me out?

Me.mobjGoogleMap.AddMarker(“test”, Me.sngLastLat, Me.sngLastLon, “icon: http://www.domain.com/path/to/marker/icon.png”)

https://developers.google.com/maps/documentation/javascript/3.exp/reference#MarkerOptions

  • You must to post comments
Best Answer
0
0

Sorry, my fault. I thought it was javascript code.

Wisej automatically converts any object, including anonymous objects, to JSON.  So the options object can be a an instance of a class that you define in your code, or an anonymous type. All the member names are converted using camel casing.

The anonymous definition in VB looks like this.

Me.mobjGoogleMap.AddMarker("test", Me.sngLastLat, Me.sngLastLon, New With {.icon = "http://www.domain.com/path/to/marker/icon.png"})

.icon can also be .Icon.

Or you can define an options class and to this:

Dim options as New MarkerOptions()
options.Icon = "http://www.domain.com/path/to/marker/icon.png"
Me.mobjGoogleMap.AddMarker("test", Me.sngLastLat, Me.sngLastLon, options)

 

  • You must to post comments
0
0

i find the solution in c#

 

dynamic markerOptions = new
{
position = new { lat, lon }, // Ejemplo: Ciudad de México
map = wsj__Map,
icon = new
{
url = “https://e7.pngegg.com/pngimages/912/661/png-clipart-computer-icons-location-location-icon-map-location-icon-miscellaneous-desktop-wallpaper-thumbnail.png”, // URL de la imagen del ícono
scaledSize = new { width = 10, height = 10 }, // Tamaño del ícono
origin = new { x = 0, y = 0 }, // Punto de origen
anchor = new { x = 25, y = 50 } // Punto de anclaje
}
};

this.wsj__Map.AddMarker(“Test”, lat, lon, markerOptions, true);

  • You must to post comments
0
0

Thank you for that excellent explanation. I will read more about anonymous objects. The code is working.

  • You must to post comments
0
0

That doesn’t compile in VB. I tried putting the braces inside the quotes, and that didn’t work either…

Me.mobjGoogleMap.AddMarker(“test”, Me.sngLastLat, Me.sngLastLon, “{icon: http://www.domain.com/path/to/marker/icon.png}”)

  • You must to post comments
0
0

Try this: { insted of ”

Me.mobjGoogleMap.AddMarker(“test”, Me.sngLastLat, Me.sngLastLon, {icon: “http://www.domain.com/path/to/marker/icon.png”})

Options usually are javascript maps.

  • You must to post comments
Showing 5 results
Your Answer

Please first to submit.