JavaScript: Add marker function on Google Map
Problem :
You want to create add marker Javascript function to put markers on Google Map canvas. How to do that?
Solution :
Below is a code fragment from previous tutorial on how to convert IP address to location in Golang.
var map;
function showMap(latitude, longitude, ipaddress) {
var pos = new google.maps.LatLng(latitude, longitude);
var mapOptions = {
zoom: 5,
center: pos,
mapTypeId: google.maps.MapTypeId.ROADMAP,
content: 'Location found by IP Address'
};
var mapDiv = document.getElementById("map-canvas");
map = new google.maps.Map(mapDiv, mapOptions);
var title = ipaddress + " location";
addMarker(map, pos, title, "");
}
function addMarker(map, latlong, title, content) {
var markerOptions = {
position: latlong,
map: map,
title: title,
clickable: true
};
var marker = new google.maps.Marker(markerOptions);
}
Hope this helps and happy coding!
References :
https://developers.google.com/maps/documentation/javascript/examples/marker-simple
https://www.socketloop.com/tutorials/golang-find-location-by-ip-address-and-display-with-google-map
See also : Golang : Find location by IP address and display with Google Map
By Adam Ng
IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.
Advertisement
Tutorials
+4.3k Golang : Scan forex opportunities by Bollinger bands
+3.1k Python : Find out the variable type and determine the type with simple test
+7.7k Golang : How to protect your source code from client, hosting company or hacker?
+25.6k Golang : How to convert(cast) string to IP address?
+7.2k Golang : Go as a script or running go with shebang/hashbang style
+8.3k Golang : How to tokenize source code with text/scanner package?
+8.9k Golang : Removes punctuation or defined delimiter from the user's input
+5.8k Golang : Grayscale Image
+3k Javascript : Access JSON data example
+16.6k Golang : Check if directory exist and create if does not exist
+19.4k Golang : How to reverse slice or array elements order
+8.1k Golang : Get login name from environment and prompt for password