rock rock - 3 months ago 10
PowerShell Question

How to calculate the distance between different cities by PowerShell?

I am doing a project which needs to calculate the distance between different cities in the world. I think there is a way with google maps, but I do not know how to use it within PowerShell.

I found something new from Get location (lat/long) from googlemap with address - Using powershell.

The answer to that question is quite useful, but the coordinates I got can't be directly used to calculate the distance.
I've tried to use

[Single]
,
[Int]
or
[Double]
to change the data type. But it gave me the error
Cannot convert the "System.Decimal" value of type "System.RuntimeType" to type "System.Double".


Any method can convert the data type?

Answer

To answer the conversion part of this question (using the example from the other question you referenced), the following will give you a decimal variable:

$lat = $json.results.geometry.location.lat

This will convert it to a double (for example):

$lat = [double]$json.results.geometry.location.lat