admin管理员组文章数量:1415644
I already searched in a lot of websites for a solution but no one of them worked.
Since hours I am trying to get the name of the city by using the latitude and longitude values which I will get from a input box to my x
, y
variables but no example worked.
I also read in the Google maps API but it was not useful.
I already have an API key.
Do you maybe have any solution?
This example I got from the website and tried but without success:
function myFunction() { var x='xxxxx'; var y='xxxxx'; //my coordinates
var geocoder = new google.maps.Geocoder;
var latlng = {lat: parseFloat(x), lng: parseFloat(y)};
geocoder.geocode({'location': latlng}, function(results, status) {
if (status === google.maps.GeocoderStatus.OK) {
// ...
} else {
window.alert('No results found');
}
} else {
window.alert('Geocoder failed due to: ' + status);
}
});
}
I already searched in a lot of websites for a solution but no one of them worked.
Since hours I am trying to get the name of the city by using the latitude and longitude values which I will get from a input box to my x
, y
variables but no example worked.
I also read in the Google maps API but it was not useful.
I already have an API key.
Do you maybe have any solution?
This example I got from the website and tried but without success:
function myFunction() { var x='xxxxx'; var y='xxxxx'; //my coordinates
var geocoder = new google.maps.Geocoder;
var latlng = {lat: parseFloat(x), lng: parseFloat(y)};
geocoder.geocode({'location': latlng}, function(results, status) {
if (status === google.maps.GeocoderStatus.OK) {
// ...
} else {
window.alert('No results found');
}
} else {
window.alert('Geocoder failed due to: ' + status);
}
});
}
Share
Improve this question
edited Nov 26, 2016 at 21:27
jrbedard
3,7245 gold badges35 silver badges35 bronze badges
asked Nov 24, 2016 at 17:04
sinantosinanto
111 silver badge1 bronze badge
4
- 1 Give this a try: stackoverflow./questions/6797569/… – Bassie Commented Nov 24, 2016 at 17:06
- geocodezip./v3_GoogleEx_geocoding-reverse2postcodeD.html – geocodezip Commented Nov 24, 2016 at 17:11
- Wow thats it thank you :) LOVE THIS SITE ! – sinanto Commented Nov 24, 2016 at 18:29
- Possible duplicate of How can I get city name from a latitude and longitude point? – Maksim Simkin Commented Nov 24, 2016 at 19:38
1 Answer
Reset to default 3Look out for Geo location API
Sample Request
http://maps.googleapis./maps/api/geocode/json?latlng=40.714224,-73.961452&sensor=false
本文标签: google mapsHow to find city name with latitude and longitude in JavaScriptStack Overflow
版权声明:本文标题:google maps - How to find city name with latitude and longitude in JavaScript? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745243389a2649443.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论