【问题标题】:Javascript : find a city using latitude/longitude?Javascript:使用纬度/经度查找城市?
【发布时间】:2012-12-14 09:31:40
【问题描述】:

我有一个 XML 文件,其中包含气象测量值及其纬度和经度。 我想用Javascript找到与给定纬度和经度相对应的城市。我该怎么办?

感谢您的回答

【问题讨论】:

标签: javascript xml location latitude-longitude


【解决方案1】:
// To initialisation Map and GeoCoder
var geocoder = new google.maps.Geocoder();
var infowindow = new google.maps.InfoWindow(); 
var marker,map;
var directionsDisplay;
var directionsService = new google.maps.DirectionsService();

 directionsDisplay = new google.maps.DirectionsRenderer();
            var chicago = new google.maps.LatLng(41.850033, -87.6500523);
            var mapOptions = {
                zoom: 6,
                mapTypeId: google.maps.MapTypeId.ROADMAP,
                center: chicago
            }

 map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);

// It is called Reverse Geocoding

      var latlng = new google.maps.LatLng(41.850033, -87.6500523);
        geocoder.geocode({'latLng': latlng}, function(results, status) {
          if (status == google.maps.GeocoderStatus.OK) {
            if (results[1]) {
              map.setZoom(11);
              marker = new google.maps.Marker({
                  position: latlng,
                  map: map
              });
              infowindow.setContent(results[1].formatted_address);
              infowindow.open(map, marker);
            } else {
              alert('No results found');
            }
          } else {
            alert('Geocoder failed due to: ' + status);
          }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-25
    • 2014-06-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多