Skip to content

Instantly share code, notes, and snippets.

@DragonOsman
Created November 8, 2017 19:52
Show Gist options
  • Save DragonOsman/4570d8a1919b2d4146d72acccc79895f to your computer and use it in GitHub Desktop.
Save DragonOsman/4570d8a1919b2d4146d72acccc79895f to your computer and use it in GitHub Desktop.
var map, infoWindow;
function initMap() {
map = new google.maps.Map(document.getElementById('map'), {
center: { lat: -34.397, lng: 150.644 },
zoom: 6
});
infoWindow = new google.maps.InfoWindow;
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function (position) {
var pos = {
lat: position.coords.latitude,
lng: position.coords.longitude
};
infoWindow.setPosition(pos);
var form = document.createElement("form");
form.method = "post";
form.action = "main.cpp";
var fieldset = document.createElement("fieldset");
fieldset.value = "Enter money amount";
var text_field = document.createElement("input");
text_field.type = "text";
text_field.name = "money_amount";
text_field.placeholder = "Enter amount";
fieldset.appendChild(text_field);
var fieldset2 = document.createElement("fieldset");
fieldset2.value = "Pick from and to currency";
var from_currency_select = document.createElement("select");
var to_currency_select = document.createElement("select");
from_currency_select.id = "from";
to_currency_select.id = "to";
var currencies = ["ALL", "AFN", "ARS", "AWG", "AUD", "AZN", "BSD", "BBD", "BYN", "BZD", "BMD", "BOB",
"BAM", "BWP", "BGN", "BRL", "BND", "KHR", "CAD", "KYD", "CLP", "CNY", "COP", "CRC", "HRK", "CUP", "CZK",
"DKK", "DOP", "XCD", "EGP", "SVC", "EUR", "FKP", "FJD", "GHS", "GIP", "GTQ", "GGP", "GYD", "HNL", "HKD",
"HUF", "ISK", "INR", "IDR", "IRR", "IMP", "ILS", "JMD", "JPY", "JEP", "KZT", "KPW", "KRW", "KGS", "LAK",
"LBP", "LRD", "MKD", "MYR", "MUR", "MXN", "MNT", "MZN", "NAD", "NPR", "ANG", "NZD", "NIO", "NGN", "NOK",
"OMR", "PKR", "PAB", "PYG", "PEN", "PHP", "PLN", "QAR", "RON", "RUB", "SHP", "SAR", "RSD", "SCR", "SGD",
"SBD", "SOS", "ZAR", "LKR", "SEK", "CHF", "SRD", "SYP", "TWD", "THB", "TTD", "TRY", "TVD", "UAH", "GBP",
"USD", "UYU", "UZS", "VEF", "VND", "YER", "ZWD"];
for (var i = 0; i < currencies.length; i++)
{
var from_option = document.createElement("option");
var to_option = document.createElement("option");
from_option.value =
to_option.value =
from_option.innerHTML =
to_option.innerHTML = currencies[i];
from_currency_select.appendChild(from_option);
to_currency_select.appendChild(to_option);
}
fieldset2.appendChild(from_currency_select);
fieldset2.appendChild(to_currency_select);
form.appendChild(fieldset);
form.appendChild(fieldset2);
var submit_button = document.createElement("input");
submit_button.name = "convert_currency";
submit_button.type = "submit";
submit_button.value = "Submit";
form.appendChild(submit_button);
document.body.appendChild(form);
infoWindow.setContent(form);
infoWindow.open(map);
map.setCenter(pos);
}, function () {
handleLocationError(true, infoWindow, map.getCenter());
});
} else {
handleLocationError(false, infoWindow, map.getCenter());
}
}
function handleLocationError(browserHasGeolocation, infoWindow, pos) {
infoWindow.setPos(pos);
infoWindow.setContent(browserHasGeolocation ?
'Error: The Geolocation service failed.' :
'Error: Your browser doesn\'t support geolocation.');
infoWindow.open(map);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment