提问者:小点点

如何在不知道纬度和经度的情况下根据地名查看地图?[副本]


我想在网页上显示小地图。我只有地名。我没有地方的纬度和经度。假设我的地方是“AH Wadia Marg,朋友殖民地,哈洛普勒,库拉,孟买,马哈拉施特拉邦400070

有什么办法显示吗?


共2个答案

匿名用户

我不完全确定你想要什么,但是谷歌地图API允许你只根据名字显示一个位置。

如果你想要一个静态图片:https://developers . Google . com/maps/documentation/static maps/

如果需要交互式地图:https://developers.google.com/maps/documentation/embed/guide

匿名用户

您需要使用谷歌地理代码,首先您需要收集整个地址并制作逗号分隔字符串,然后需要传递给地理代码,请查看下面的代码。

var geocoder = new google.maps.Geocoder();

var address = $("#address").val() + ' ' + $("#city").val() + ' ' + $("#state").val() + ' ' + $("#zipcode").val();

    if (geocoder) {                                                                                    

geocoder.geocode({'address': address}, function (results, status) {
                                                                                                if (status == google.maps.GeocoderStatus.OK) {
                                                                                            $('#LoadMap').locationpicker({
                                                                                                location: {latitude: results[0].geometry.location.k, longitude: results[0].geometry.location.D},
                                                                                                radius: 300,
                                                                                                inputBinding: {
                                                                                                    locationNameInput: $('#AddressAutoComplete')
                                                                                                },
                                                                                                enableAutocomplete: true,
                                                                                                onchanged: function (currentLocation, radius, isMarkerDropped) {
                                                                                                    $('#address_loc0').val(currentLocation.latitude + ',' + currentLocation.longitude);                                                                                                                                                                                                        
                                                                                                }    
                                                                                            });
                                                                                        }                                                                                         
                                                                                    });
}