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
+6.6k Golang : Output or print out JSON stream/encoded data
+14.4k Golang : Send email with attachment(RFC2822) using Gmail API example
+7.2k Golang : Example of custom handler for Gorilla's Path usage.
+11.2k Use systeminfo to find out installed Windows Hotfix(s) or updates
+8.6k Golang : On lambda, anonymous, inline functions and function literals
+11.3k Golang : Delay or limit HTTP requests example
+13.8k Golang : How to check if a file is hidden?
+10.2k Golang : cannot assign type int to value (type uint8) in range error
+20.7k Golang : Underscore or snake_case to camel case example
+19.9k Golang : Reset or rewind io.Reader or io.Writer
+7.4k Gogland : Single File versus Go Application Run Configurations
+13.9k Golang : Compress and decompress file with compress/flate example