Created
April 4, 2020 20:50
-
-
Save Andrew67/0e9498daa29f9bb5f820796ca7aa49f8 to your computer and use it in GitHub Desktop.
Google Maps Static API URL Builder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Google Maps Static API URL Builder | |
// Sets up a map with a marker to the "current location" and up to 9 other markers for location results | |
// Note: input to the functions is not validated or sanitized; this is an extract previously used in another project | |
// LICENSE: Public Domain | |
function MapBuilder() { | |
this.url = 'https://maps.google.com/maps/api/staticmap?size=288x216&scale=2&key=API_KEY'; | |
this.nextMarkerNumber = 0; | |
} | |
MapBuilder.prototype.getURL = function() { return this.url; }; | |
MapBuilder.prototype.addMyLocationMarker = function(coords) { // Coords in "lat,lng" format | |
this.url += '&markers='+coords; | |
}; | |
MapBuilder.prototype.addMarker = function(coords) { // Warning: Static Maps API limited to 9 for labels | |
this.url += '&markers=color:blue|label:'+(++this.nextMarkerNumber)+'|'+coords; | |
}; | |
var locationMap = new MapBuilder(); | |
locationMap.addMyLocationMarker(position.coords.latitude + ',' + position.coords.longitude); | |
locationMap.addMarker(locations[i].lat + ',' + locations[i].lng); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment