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
+34.1k Golang : How to stream file to client(browser) or write to http.ResponseWriter?
+38.7k Golang : How to iterate over a []string(array)
+26.4k Golang : How to check if a connection to database is still alive ?
+5.9k Golang : Get Hokkien(福建话)/Min-nan(閩南語) Pronounciations
+6.5k Golang : Calculate pivot points for a cross
+47.2k Golang : Convert int to byte array([]byte)
+11.1k Golang : Find age or leap age from date of birth example
+5.9k Golang : Get missing location after unmarshal binary and gob decode time.
+12.9k Golang : Convert(cast) int to int64
+15.3k Golang : Get digits from integer before and after given position example
+8.5k Golang : Get final balance from bit coin address example
+13.7k Golang: Pad right or print ending(suffix) zero or spaces in fmt.Printf example