Geonames Servcie API を使用して、ユーザーの現在地の国コードを取得しようとしています。geonames サービス API は 3 文字の国コードではなく 2 文字の国コードを返し、3 文字の国コードが必要だと思います。このため、2 文字の国コードと 3 文字の国コードの間のマッピングを作成しました。
以下は私のコードです。何らかの方法で、アラート ボックスがまったく機能しません。私は何かが欠けていると確信していますか?
<html>
<head>
<title>Visitor's location</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script>
$(document).ready( function() {
$.getJSON('http://ws.geonames.org/countryCode', {
lat: position.coords.latitude,
lng: position.coords.longitude,
type: 'JSON'
}, function(result) {
alert('Country: ' + result.countryName + '\n' + 'Code: ' + result.countryCode);
$('#newURL').attr('href','https://www.google.com&jobid='+result.countryCode);
});
});
</script>
</head>
<body>
<a id="newURL">URL</a>
</body>
</html>
上記のコードで何が間違っていますか? 以下は、コンソールに表示されるエラーです。
Uncaught ReferenceError: position is not defined