从google map api v3获取地址 [英] Get address from google map api v3 in English
问题描述
我使用谷歌地图api v3从一个点获取坐标和地址,但谷歌返回地址用法语。这里是我用来获取地址的脚本,我如何强制Google地图返回英文结果。
var map;
var geocoder;
var mapOptions = {center:new google.maps.LatLng(0.0,0.0),zoom:2,
mapTypeId:google.maps.MapTypeId.ROADMAP};
函数initialize(){
var myOptions = {
center:new google.maps.LatLng(36.835769,10.247693),
zoom:15,
mapTypeId:google.maps.MapTypeId.ROADMAP
};
geocoder = new google.maps.Geocoder();
var map = new google.maps.Map(document.getElementById(map_canvas),
myOptions);
google.maps.event.addListener(map,'click',function(event){
placeMarker(event.latLng);
});
var marker;
函数placeMarker(location){
if(marker){//在vérifiesi le marqueur existe
marker.setPosition(location); //关于更改位置
}其他{
marker = new google.maps.Marker({//关于crééle marqueur
位置:location,
map:map
});
}
document.getElementById('lat')。value = location.lat();
document.getElementById('lng')。value = location.lng();
getAddress(location);
函数getAddress(latLng){
geocoder.geocode({'latLng':latLng},
函数(结果,状态){
if(status == google.maps.GeocoderStatus.OK){
if(results [0]){
document.getElementById(address)。value = results [0] .formatted_address;
else {
document.getElementById(address)。value =没有结果;
}
}
else {
document .getElementById(address)。value = status;
}
});
$ div $解析方案
到文档,您可以更改maps API演示文稿的语言通过添加 language
参数,如下所示:
<脚本类型=text / javascriptsrc =http://maps.googleapis.com/maps/api/js?sensor=false&language=ja>
另外,根据这个答案,您可以使用 google.load
命令更改使用的服务,如下所示:
< script type =text / javascript>
google.load(maps,2,{language:de,base_domain:'google.de'});
...
< / script>
(代码取自链接的问题)。以下是google.load的文档的链接。我在考虑改变base_domain会达到理想的结果,但我还没有测试过。
I use google map api v3 to get coordinate and address from a point, but google return address in French. Here the script i use to get the address, how can I force Google map to return the result in English.
var map;
var geocoder;
var mapOptions = { center: new google.maps.LatLng(0.0, 0.0), zoom: 2,
mapTypeId: google.maps.MapTypeId.ROADMAP };
function initialize() {
var myOptions = {
center: new google.maps.LatLng(36.835769, 10.247693 ),
zoom: 15,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
geocoder = new google.maps.Geocoder();
var map = new google.maps.Map(document.getElementById("map_canvas"),
myOptions);
google.maps.event.addListener(map, 'click', function(event) {
placeMarker(event.latLng);
});
var marker;
function placeMarker(location) {
if(marker){ //on vérifie si le marqueur existe
marker.setPosition(location); //on change sa position
}else{
marker = new google.maps.Marker({ //on créé le marqueur
position: location,
map: map
});
}
document.getElementById('lat').value=location.lat();
document.getElementById('lng').value=location.lng();
getAddress(location);
}
function getAddress(latLng) {
geocoder.geocode( {'latLng': latLng},
function(results, status) {
if(status == google.maps.GeocoderStatus.OK) {
if(results[0]) {
document.getElementById("address").value = results[0].formatted_address;
}
else {
document.getElementById("address").value = "No results";
}
}
else {
document.getElementById("address").value = status;
}
});
}
}
According to the documentation you can change the language of presentation of the maps API by adding a language
parameter, like so:
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false&language=ja">
Alternatively, according to this answer, you can change the service used using the google.load
command, like so:
<script type="text/javascript">
google.load("maps", "2",{language: "de",base_domain: 'google.de'});
...
</script>
(code taken from linked question). Here's a link to the documentation for google.load. I'm thinking changing the base_domain will achieve the desired result, but I haven't tested it.
这篇关于从google map api v3获取地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!