【问题标题】:How to get view of map based on place name wihout knowing latitude and longitude? [duplicate]如何在不知道经纬度的情况下根据地名查看地图? [复制]
【发布时间】:2015-06-08 06:40:52
【问题描述】:

我想在网页中显示小地图。我只有地名。我没有地方的纬度和经度。 假设我的位置是 "AH Wadia Marg, Friends Colony, Hallow Pul, Kurla, Mumbai, Maharashtra 400070"

有没有办法显示?

【问题讨论】:

  • 为什么不对这个地方进行地理定位?
  • 该站点无法以这种方式工作(按需提供代码)。您必须进行研究,并自己创建一些代码。如果此时您仍然有问题,那么这里的其他用户可以帮助您。见How to Ask。
  • 您需要为此提供服务。谷歌提供了这样的服务。您也可以在 google 上搜索 google 服务(好吧,也许不是那么好笑的笑话 :))。
  • 当我搜索所有代码都是基于纬度和经度
  • <script type="text/javascript"> function initialize() { var latlng = new google.maps.LatLng(<?php echo $lat; ?>, <?php echo $long; ?>); var addressMarker = new google.maps.LatLng(<?php echo $lat; ?>, <?php echo $long; ?>); var myOptions = { zoom: 16, center: latlng, mapTypeId: google.maps.MapTypeId.ROADMAP }; var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); marker = new google.maps.Marker({ map:map, position: addressMarker }); } </script>

标签: javascript php jquery google-maps


【解决方案1】:

我不完全确定您想要什么,但 Google Maps API 允许您仅根据名称显示位置。

如果你想要一张静态图片: https://developers.google.com/maps/documentation/staticmaps/

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

【讨论】:

    【解决方案2】:

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

    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);                                                                                                                                                                                                        
                                                                                                    }    
                                                                                                });
                                                                                            }                                                                                         
                                                                                        });
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-07-24
      • 1970-01-01
      • 2011-11-27
      • 2014-03-30
      • 2016-01-03
      • 2017-03-28
      • 1970-01-01
      相关资源
      最近更新 更多