2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

概要

paiza.ioでelixirやってみた。
練習問題やってみた。

練習問題

api叩いて、住所から、緯度経度、求めて、地球儀上にピンを立てよ。

サンプルコード

:inets.start
:ssl.start

IO.puts """
<html lang="ja">
    <head>
        <meta charset="UTF-8" />
        <title>test</title>
        <link href="style.css" rel="stylesheet" />
        <script src="https://cesium.com/downloads/cesiumjs/releases/1.99/Build/Cesium/Cesium.js"></script>
        <link href="https://cesium.com/downloads/cesiumjs/releases/1.99/Build/Cesium/Widgets/widgets.css" rel="stylesheet" />
        <style>
body {
    padding: 0;
    margin: 0;
    overflow: hidden;
    height: 100%;
}
#cesiumContainer {
    display: flex;
    width: 100%;
    height: 100%;
}
        </style>
    </head>
    <body>
        <div id="cesiumContainer"></div>
		<script>
const viewer = new Cesium.Viewer('cesiumContainer', {	
	timeline: false
});
const pinBuilder = new Cesium.PinBuilder();
function pin(longitude, latitude) {
	const bluePin = viewer.entities.add({
		name: "red pin",
		position: Cesium.Cartesian3.fromDegrees(longitude, latitude),
		billboard: {
			image: pinBuilder.fromColor(Cesium.Color.RED, 10).toDataURL(),
			verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
		},
	});
	viewer.camera.flyTo({	 
		destination : Cesium.Cartesian3.fromDegrees(longitude, latitude, 450000)
	});
}

"""

query = URI.encode_query(%{q: "山形県東置賜郡川西町"})
url = "https://msearch.gsi.go.jp/address-search/AddressSearch?" <> query
url = String.to_charlist(url)
{:ok, {_status, _headers, body}} = :httpc.request(url)
body
body = IO.iodata_to_binary(body)
body = String.replace(body, "\\", " ")
Regex.scan(~r/:\[(.+?)\]/, body)
|> Enum.map(fn [_, v] -> 
    IO.puts("pin( #{v});")
end)


IO.puts """
		</script>
	</body>
</html>
"""

実行結果

image.png

成果物

以上。

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?