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
+17.2k Golang : Get future or past hours, minutes or seconds
+5k Golang : The Tao of importing package
+7.1k Golang : Not able to grep log.Println() output
+19.9k Golang : Check if os.Stdin input data is piped or from terminal
+22.7k Golang : Calculate time different
+7k Golang : Use modern ciphers only in secure connection
+25.1k Golang : Convert long hexadecimal with strconv.ParseUint example
+9.2k Golang : Terminate-stay-resident or daemonize your program?
+9.5k Golang : Populate slice with sequential integers example
+32.8k Delete a directory in Go
+11.3k Golang : Handle API query by curl with Gorilla Queries example
+13.2k Golang : Read from buffered reader until specific number of bytes