将坐标转换为地址v3 google api

时间:2013-10-10 14:04:29

标签: google-maps google-maps-api-3

我无法将我的坐标转换为地址... 几乎得到了下面的调整功能......但是有多少个标记,只创建了最后一个标记......:

我创建标记的功能:

    function createMarker(point,info,map) {
    var iconURL = 'img/pata.png';               
    var iconSize = new google.maps.Size(32,34);
    var iconOrigin = new google.maps.Point(0,0);    
    var iconAnchor = new google.maps.Point(15,30);

    var myIcon = new google.maps.MarkerImage(iconURL, iconSize, iconOrigin, iconAnchor);

    var marker = new google.maps.Marker({
      position : point,
      html : info,
      map : map,
      icon: myIcon
    });

    var infowindow = new google.maps.InfoWindow({
        content: "Dispositivo: " + info + "<br> Endereço: " + point

    });

    google.maps.event.addListener(marker, 'click', function() {
        infowindow.open(map,this);
      });

  }

我创建书签的功能: 试图适应的功能(只是想发送坐标并转换为地址并在点击时离开信息窗口)

    function codeLatLng() {
  var input = document.getElementById('latlng').value;
  var latlngStr = input.split(',', 2);
  var lat = parseFloat(latlngStr[0]);
  var lng = parseFloat(latlngStr[1]);
  var latlng = new google.maps.LatLng(lat, lng);
  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);
    }
  });
}

1 个答案:

答案 0 :(得分:0)

能,

但不知道如何单独获取地址列表... 但得到了点击信息:

function createMarkerAtual(point,info,dt,map) {
    var iconURL = 'img/dog2.png';               
    var iconSize = new google.maps.Size(45,45);
    var iconOrigin = new google.maps.Point(0,0);    
    var iconAnchor = new google.maps.Point(15,30);

    var myIcon = new google.maps.MarkerImage(iconURL, iconSize, iconOrigin, iconAnchor);

    var marker = new google.maps.Marker({
      position : point,
      html : info,
      map : map,
      icon: myIcon
    });

    google.maps.event.addListener(marker, 'click', function() {
        endereco(info,this.position);
        infowindow.open(map,this);
    });

  } 

function endereco(info,point){
    var geocoder = new google.maps.Geocoder();
    geocoder.geocode({'latLng': point}, function(results, status){
        if (status == google.maps.GeocoderStatus.OK){
            infowindow.setContent('<b>Coordenadas: </b>' + point + '<br><b>Dispositivo:</b> ' + info + '<br><b>Endereço: </b>' + results[0].formatted_address);
        } else {

        }
    });
}