0

I have a XML file containing meteorological measures with their latitudes and longitudes. I want to find the city corresponding to a given latitude and longitude with Javascript. How should I do ?

Thanks for your answers

4

1 回答 1

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);
          }
于 2012-12-14T10:08:58.567 回答