Google maps Google fusion表数据和将图像更改为标记

Google maps Google fusion表数据和将图像更改为标记,google-maps,show,marker,Google Maps,Show,Marker,这是我的问题。我想将不同的图像设置为融合表给出的标准标记。我从包含点坐标的列中提取数据,但当我将此坐标与标记关联时,不会显示此坐标!我认为解决方案非常简单,但我无法得到它:。请阅读下面的章节中的问题,在这个代码的中间有一个明确的想法。谢谢 function initialize() { geocoder = new google.maps.Geocoder(); map = new google.maps.Map(document.getElementById('map_canvas'

这是我的问题。我想将不同的图像设置为融合表给出的标准标记。我从包含点坐标的列中提取数据,但当我将此坐标与标记关联时,不会显示此坐标!我认为解决方案非常简单,但我无法得到它:。请阅读下面的章节中的问题,在这个代码的中间有一个明确的想法。谢谢

 function initialize() {
  geocoder = new google.maps.Geocoder();
  map = new google.maps.Map(document.getElementById('map_canvas'), {
    center: new google.maps.LatLng(46.06454, 13.23561), //the center lat and long
    zoom: 9, //zoom

    mapTypeId: google.maps.MapTypeId.ROADMAP //the map style
  });


  //make gviz request
  setData();

}

/* GVIZ - get data from Fusion Tables */

function setData() {
  //create a viz query to send to Fusion Tables
  var query = new google.visualization.Query('http://www.google.com/fusiontables/gvizdata?tq=' + encodeURIComponent("SELECT dove FROM 781907"));

  //set the callback function that will be called when the query returns
  query.send(getData);

}

function getData(response) {

  numRows = response.getDataTable().getNumberOfRows();


  for (i = 0; i < numRows; i++) {

      var row = response.getDataTable().getValue(i,0);


    codeAddress(row);
  }
}


var geocoder;


function codeAddress(latlng) {

// HERE IS THE PROBLEM!!!!
// Test show correctly "(lat,lng)" BUT no marker showed on the map!
            document.getElementById("test").innerHTML = latlng; 
      geocoder.geocode( { 'latLng': latlng}, function(results, status) {
        if (status == google.maps.GeocoderStatus.OK) {

        var marker = new google.maps.Marker({
          map: map, 
          position: latlng
//icon: new google.maps.MarkerImage("http://www.google.com/images/icons/product/fusion_tables-32.png")

      });

    } 
  });
}
更新:根据@Trott的回答,可能是这样的?但仍然没有运行。有什么建议吗

function getData(response) {

  numRows = response.getDataTable().getNumberOfRows();

  //create an array of row values
  for (i = 0; i < numRows; i++) {
    rowtext = response.getDataTable().getValue(i,0);
    var strArr[] = rowtext.split(",");
    document.getElementById("via").innerHTML = rowtext;
    row = new google.maps.LatLng(strArr[0],strArr[1]);
    codeAddress(row);
  }
}
geocoder.geocode需要一个LatLng对象。变量latlng只是文本。您需要找到一种方法将其转换为LatLng对象。最明显的方法可能是使用正则表达式或其他方法对其进行解析,并将lat和lng传递给新的google.maps.LatLng。也许有一个更优雅的解决方案,但这会奏效

如果有帮助的话,下面是我对您的代码所做的一些快速黑客攻击,以确认我上面写的内容。我刚硬编码了你的第一对坐标。您仍然需要编写一些东西来解析数据

function codeAddress(latlng) {
//Whoops, latlng is a string.  We need it to be an object.  Let's just hardcode one for demo purposes.
latlng=new google.maps.LatLng(46.0724339, 13.249490000000037);
geocoder.geocode( { 'latLng': latlng}, function(results, status) {

        if (status == google.maps.GeocoderStatus.OK) {

        var marker = new google.maps.Marker({
          map: map,
          position: latlng,
          icon: new google.maps.MarkerImage("http://www.google.com/images/icons/product/fusion_tables-32.png")

      });

    }
  });
}
更新:如果@Massimo希望按照更新中的方式进行更新,则需要删除括号,可能还需要删除空白。尝试类似以下内容:

function getData(response) {

  numRows = response.getDataTable().getNumberOfRows();

  //create an array of row values
  for (i = 0; i < numRows; i++) {
    var rowtext = response.getDataTable().getValue(i,0);
    var sanitizedText = rowtext.replace(/[\(\)\s]/g, "");
    var strArr = sanitizedText.split(",");
    document.getElementById("via").innerHTML = rowtext;
    row = new google.maps.LatLng(strArr[0],strArr[1]);
    codeAddress(row);
  }
}

是否尝试取消对图标行的注释?确定:。从融合表中提取的坐标无法识别。如果我输入row.type。。。我没有分类你确定它们是正确的吗?lat/lng许多系统存储它们lng/lat-这已经咬了我好几次kml,看着你的伴侣-啊,不,它们是地图本身的正确方式。。意大利,对吗?您正在获取的数据是什么?相似的数字?你知道可以告诉融合表地理编码地址,不是吗?您可以将Kmlatlng导出为一个LatLng对象。在上面的代码中,它不是。下面我的答案中有更多。非常感谢,我在考虑regex,但也希望这是一种更好、更清晰的方法尝试拆分,但不是以正确的方式:s。不想花费比我已经做的更多的时间:P,所以。。。我试过了。你仍然需要去掉括号,可能还有空白。我已经更新了我的答案,谢谢!这就是解决办法!顺便说一句,var strArr不是var strArr[]