Skip to main content
added 301 characters in body
Source Link
rhermans
  • 37.4k
  • 4
  • 61
  • 152

Using an external API

ClearAll[GermanZip2GeoPosition];
GermanZip2GeoPosition[zip_String] := Block[
   {response = Import[URLBuild[Quiet@Import[URLBuild[{"https://api.zippopotam.us", "DE", zip}], "RawJSON"]},
   If[response =!= $Failed,
    Query["places", 1, 
      GeoPosition[ToExpression@{#["latitude"], #["longitude"]}] &][response]
    , Null
    ]
   ];
GermanZip2GeoPosition[zip_Integer] := GermanZip2GeoPosition[ToString[zip]]GermanZip2GeoPosition[ToString[zip]];
SetAttributes[GermanZip2GeoPosition, Listable]

Example

GeoGraphics@GeoMarker@GermanZip2GeoPosition@{90402, 90491, 90513, 90518, 90522, 90547, 90552, 90579, 90762, 90768
GeoGraphics@GeoMarker@GermanZip2GeoPosition[90402]}

Mathematica graphicsMathematica graphics


Code and plots done in Mathemathica 11.1.1 on Win7

Using an external API

ClearAll[GermanZip2GeoPosition];
GermanZip2GeoPosition[zip_String] := Block[
   {response = Import[URLBuild[{"https://api.zippopotam.us", "DE", zip}], "RawJSON"]},
   Query["places", 1, GeoPosition[ToExpression@{#["latitude"], #["longitude"]}] &][response]
   ];
GermanZip2GeoPosition[zip_Integer] := GermanZip2GeoPosition[ToString[zip]]


GeoGraphics@GeoMarker@GermanZip2GeoPosition[90402]

Mathematica graphics

Using an external API

ClearAll[GermanZip2GeoPosition];
GermanZip2GeoPosition[zip_String] := Block[
   {response = Quiet@Import[URLBuild[{"https://api.zippopotam.us", "DE", zip}], "RawJSON"]},
   If[response =!= $Failed,
    Query["places", 1, 
      GeoPosition[ToExpression@{#["latitude"], #["longitude"]}] &][response]
    , Null
    ]
   ];
GermanZip2GeoPosition[zip_Integer] := GermanZip2GeoPosition[ToString[zip]];
SetAttributes[GermanZip2GeoPosition, Listable]

Example

GeoGraphics@GeoMarker@GermanZip2GeoPosition@{90402, 90491, 90513, 90518, 90522, 90547, 90552, 90579, 90762, 90768
}

Mathematica graphics


Code and plots done in Mathemathica 11.1.1 on Win7

Source Link
rhermans
  • 37.4k
  • 4
  • 61
  • 152

Using an external API

ClearAll[GermanZip2GeoPosition];
GermanZip2GeoPosition[zip_String] := Block[
   {response = Import[URLBuild[{"https://api.zippopotam.us", "DE", zip}], "RawJSON"]},
   Query["places", 1, GeoPosition[ToExpression@{#["latitude"], #["longitude"]}] &][response]
   ];
GermanZip2GeoPosition[zip_Integer] := GermanZip2GeoPosition[ToString[zip]]


GeoGraphics@GeoMarker@GermanZip2GeoPosition[90402]

Mathematica graphics