PoshCode Archive  Artifact [6b77fa5430]

Artifact 6b77fa5430926b044671e0dbbc1bedbc47b4dffa64dad7fff9c65da731f07550:

  • File Find-GeoCode.ps1 — part of check-in [c064e6c645] at 2018-06-10 12:57:44 on branch trunk — A quick demonstration of using the MapPoint (aka Bing Maps?) web services to get addresses from Lat,Long pairs and vice-versa. Requires you to sign up for (at least) the free developer account in order to use the API. (user: Joel Bennett size: 2037)

# encoding: ascii
# api: powershell
# title: Find-GeoCode
# description: A quick demonstration of using the MapPoint (aka Bing Maps?) web services to get addresses from Lat,Long pairs and vice-versa. Requires you to sign up for (at least) the free developer account in order to use the API.
# version: 0.1
# type: function
# author: Joel Bennett
# license: CC0
# function: Find-ReverseGeoCode
# x-poshcode-id: 1490
# x-archived: 2014-12-03T03:24:02
# x-published: 2009-11-25T22:29:00
#
#
$mappoint = New-WebServiceProxy http://staging.mappoint.net/standard-30/mappoint.wsdl -Namespace MapPoint
$FindService = new-object MapPoint.FindServiceSoap
# You need an account, sign up here: https://mappoint-css.live.com/mwssignup
$FindService.Credentials = Get-Credential 

function Find-ReverseGeoCode( [double]$Latitude, [double]$longitude, [switch]$force  ) 
{
   $Coords = new-object MapPoint.LatLong
   $Coords.Latitude = $Latitude
   $Coords.Longitude = $longitude
   $Locations = $FindService.GetLocationInfo( $Coords, "MapPoint.NA", $null)

   if($force) {
      return $Locations
   } elseif($Locations[0].Address) {
      return $Locations[0].Address # .FormattedAddress + " - " + $Locations[0].Address.CountryRegion
   } else {
      return $Locations | ?{ $_.Entity.TypeName -eq "PopulatedPlace" } # | %{ $_.Entity.DisplayName }
   }
}

function Find-GeoCode( $address, $country = "US" ) 
{
   $spec = new-object MapPoint.FindAddressSpecification
   $spec.DataSourceName = "MapPoint.NA"
   $spec.InputAddress = $FindService.ParseAddress( $address,  $country )
   
   $Found = $FindService.FindAddress( $spec )
   if($Found.NumberFound) {
      $found.Results | Select -expand FoundLocation | Select -Expand LatLong
   }
   #  if($Found.NumberFound -gt 1) {
   #     $found.Results| Select -expand FoundLocation | Select -Expand Address
   #  }
}

## This is how non-geography geeks think of them:
Set-Alias Find-Address Find-ReverseGeoCode
Set-Alias Find-Coordinates Find-GeoCode