ジオコードが新しく、ジオコードが固定されています。現在位置を取得しようとしています。ジオコードを使用してplaceidを取得しようとしています。ジオコーダーがZERO_RESULTSによって失敗しました。下のコードは正常に動作しています。ZERO_RESULTSのためジオコーダーが失敗しました
var currentLatitude= 23.2147721;
var currentLongitude =72.6446714;
function initialize() {
var geocoder = new google.maps.Geocoder;
var latlng = {
lat : currentLatitude,
lng : currentLongitude
};
console.log("Geocoder" + latlng);
geocoder.geocode({
'location' : latlng
}, function(results, status) {
if (status === google.maps.GeocoderStatus.OK) {
if (results[1]) {
console.log(results[1].place_id);
} else {
window.alert('No results found');
}
} else {
window.alert('Geocoder failed due to: ' + status);
q
}
});
};
以下のコードはエラーを表しています。
var currentLatitude,currentLongitude;
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position){
currentLatitude = parseFloat(position.coords.latitude);
currentLongitude = parseFloat(position.coords.longitude);
console.log("Latitude:"+currentLatitude+"Longitude:"+currentLongitude);
});
} else {
console.log("Geolocation is not supported by this browser.");
}
function initialize() {
var geocoder = new google.maps.Geocoder;
var latlng = {
lat : currentLatitude,
lng :currentLongitude
};
console.log("Geocoder" + latlng);
geocoder.geocode({
'location' : latlng
}, function(results, status) {
if (status === google.maps.GeocoderStatus.OK) {
if (results[1]) {
console.log(results[1].place_id);
} else {
window.alert('No results found');
}
} else {
window.alert('Geocoder failed due to: ' + status);
}
});
};
私が使用しているsrcが
<script async defer
src="https://maps.googleapis.com/maps/api/js?key=YOURKEYHERE&callback=initialize">
任意のヘルプは大歓迎です –