Skip to content

Instantly share code, notes, and snippets.

@MSAdministrator
Created August 25, 2015 04:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MSAdministrator/d07789031f11529412d9 to your computer and use it in GitHub Desktop.
Save MSAdministrator/d07789031f11529412d9 to your computer and use it in GitHub Desktop.
2015-August Scripting Games Puzzle - Get-MyGeoLocation
function Get-MyGeoLocation {
param (
[parameter(HelpMessage="Please provide a save location")]
[string]$outfilepath = $("C:\users\{0}\Desktop\map.html" -f $($env:username))
)
<#
.SYNOPSIS
Map your current location on google maps
.DESCRIPTION
This function will map your current location based on information from http:\\www.telize.com/geoip
.PARAMETER outfilepath
Specifices the location that the map.html should be saved to. Default path is the current users desktop and saved as map.html
.EXAMPLE
C:\PS> Get-MyGeoLocation -outfilepath "C:\users\username\Desktop\map.html"
#>
$mylocation = Invoke-RestMethod -uri "http://www.telize.com/geoip" | select longitude,latitude,continent_code,timezone
Write-Verbose $mylocation
$html=@"
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<title>My Location</title>
<style>
html, body {
height: 100%;
margin: 0;
padding: 0;
}
#map {
height: 100%;
}
</style>
</head>
<body>
<div id="map"></div>
<script>
function initMap() {
var map2;
var bounds = new google.maps.LatLngBounds();
var mapOptions = {
mapTypeId: 'roadmap'
};
// Display a map on the page
map2 = new google.maps.Map(document.getElementById("map"), mapOptions);
// Multiple Markers
var markers = [ [$($mylocation.latitude),$($mylocation.longitude)] ];
var marker, i;
// Loop through our array of markers & place each one on the map
var marker, i
var labels = '0123456789';
var labelIndex = 0;
for( i = 0; i < markers.length; i++ ) {
var position = new google.maps.LatLng(markers[i][0],markers[i][1]);
bounds.extend(position);
marker = new google.maps.Marker({
map: map2,
label: labels[labelIndex++ % labels.length],
position: position
});
}
map2.fitBounds(bounds);
}
</script>
<script async defer
src="https://maps.googleapis.com/maps/api/js?signed_in=true&callback=initMap"></script>
</body>
</html>
"@ | Out-File $outfilepath
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment