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
+9.1k Golang : Get current, epoch time and display by year, month and day
+6.7k Golang : Rename part of filename
+15.7k Golang : File path independent of Operating System
+10.8k Golang : Calculations using complex numbers example
+9k Golang : Function wrapper that takes arguments and return result example
+9.2k Golang : Get escape characters \u form from unicode characters
+6.7k Javascript : Push notifications to browser with Push.js
+4.6k PHP : Hide PHP version information from curl
+5.4k Golang : Build new URL for named or registered route with Gorilla webtoolkit example
+4.1k Nginx and PageSpeed build from source CentOS example
+12.4k Golang : error parsing regexp: invalid or unsupported Perl syntax
+13k Golang : convert rune to unicode hexadecimal value and back to rune character