将lat,lng转换为Address并在infoWindow google map api上显示 [英] Convert lat,lng into Address and show on infoWindow google map api

查看:135
本文介绍了将lat,lng转换为Address并在infoWindow google map api上显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有对象列表中的lat,lng值

I have list of lat, lng values in object

var path = [{"lat":"12.9247903824","lng":"77.5806503296"},{"lat":"10.9974470139","lng":"76.9459457397"}]

在这里,我必须将latlng转换为地址,并且必须显示标记和infowindow。地址必须显示在信息窗口中

Here i have to convert latlng into address and have to show marker and infowindow. Address have to be shown in info window

我试过这一个,我得到地址和多个标记,但我无法在信息窗口中显示地址.. last infowindow只显示地址

I have tried this one, i have getting address and multiple markers but i not able to show address on info windows.. last infowindow only showing address

for (var i = 0; i < path.length; i++) {
    var pos = new google.maps.LatLng(path[i]["lat"], path[i]["lng"]);

    var marker = new google.maps.Marker({
        position: pos,
        map: map
    });

    geocoder.geocode({'latLng': pos}, function(results, status) {
        if (status == google.maps.GeocoderStatus.OK) {
            infowindow.setContent(results[i].formatted_address);
        } else {
            alert('Geocoder failed due to: ' + status);
        }
    });
}


推荐答案

点击标记时打开信息窗口?在该侦听器中插入geocoder函数,执行地理编码,将内容设置为infowindow,然后打开infowindow。

Do you have a listener to open the infowindow when you click a marker? Insert the geocoder function inside that listener, do the geocode, set content to the infowindow and then open the infowindow.

这篇关于将lat,lng转换为Address并在infoWindow google map api上显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆