0

我随机创建了几个带有客户端地址(少于 3000 个)的 CSV 文件。我可以将其发送到 Google 地图引擎以生成地图视图吗?(尝试自动化而不是直接删除文件)谢谢

4

2 回答 2

0

您可以使用 Maps Engine API将行插入现有表将数据文件(CSV、KML、形状文件)上传到新表

这里唯一的问题是 API 仅在核心“地图引擎”产品上受支持,而不是 Lite 或 Pro 产品。如果您想进行实验,可以使用直接Maps Engine产品的免费层级。

于 2014-01-28T22:31:11.163 回答
0

我的要求很简单,并找到了一种简单的方法来解决它。只是在运行时生成了一个 HTML 页面,其中所有文本地址都插入到 JavaScript 数组中,然后循环通过它来生成地理编码和标记的位置。唯一的缺点是性能,这是因为谷歌需要以大约 1 秒的间隔连续的地理编码请求。我使用 VBA 代码生成 HTML

<!DOCTYPE html>
<html>
    <head>
        <meta charset='utf-8'>
        <meta http-equiv='X-UA-Compatible' content='IE=edge,chrome=1'>
        <title>Data : geographically linked</title>
        <script src='http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js'></script>
        <script src='https://maps.googleapis.com/maps/api/js?v=3.11&sensor=false' type='text/javascript'></script>
        <script type='text/javascript'> 
        // check DOM Ready
        $(document).ready(function() {
            // execute
            (function() {
                /////////////// Addresses ///////////////////
                var locations = new Array();
                var i = 0;
                locations[i++] = 'L,Riversea: office Loc1,1 Wallace Lane Mosman Park WA 6012'
                locations[i++] = 'C,Wearne: office Loc2,3 Gibney St Cottesloe WA 6011'
                locations[i++] = 'S,Beachside: office Loc3,621 Two Rocks Rd Yanchep WA 6035'
                /////// Addresses/////////
                var total_locations = i;
                i = 0;
                console.log('About to look up ' + total_locations + ' locations');
                // map options
                var options = {
                    zoom: 10,
                    center: new google.maps.LatLng(-31.982484, 115.789329),//Bethanie  
                    mapTypeId: google.maps.MapTypeId.HYBRID,//TERRAIN/ ROADMAP/ SATELLITE
                    mapTypeControl: true
                };
                // init map
                console.log('Initialise map...');
                var map = new google.maps.Map(document.getElementById('map_canvas'), options);
               // use the Google API to translate addresses to GPS coordinates 
               //(See Limits: https://developers.google.com/maps/documentation/geocoding/#Limits)
                var geocoder = new google.maps.Geocoder();
                if (geocoder) {
                    console.log('Got a new instance of Google Geocoder object');
                    // Call function 'createNextMarker' every second
                    var myVar = window.setInterval(function(){createNextMarker()}, 700);
                    function createNextMarker() {
                        if (i < locations.length) 
                       {
                            var customer = locations[i];
                            var parts = customer.split(','); // split line into parts (fields)
                            var type= parts.splice(0,1);    // type from location line (remove)
                            var name = parts.splice(0,1);    // name from location line(remove)
                            var address =parts.join(',');   // combine remaining parts
                            console.log('Looking up ' + name + ' at address ' + address);
                            geocoder.geocode({ 'address': address }, makeCallback(name, type));
                            i++; // next location in list
                            updateProgressBar(i / total_locations);


                        } else 
                       {
                            console.log('Ready looking up ' + i + ' addresses');
                            window.clearInterval(myVar);
                        }
                    }

                    function makeCallback(name,type) 
                   {
                        var geocodeCallBack = function (results, status) {
                            if (status == google.maps.GeocoderStatus.OK) {
                                var longitude = results[0].geometry.location.lng();
                                var latitude = results[0].geometry.location.lat();
                                console.log('Received result: lat:' + latitude + ' long:' + longitude);
                                var marker = new google.maps.Marker({
                                    position: new google.maps.LatLng(latitude, longitude),
                                    map: map,
                                    title: name + ' : ' + '\r\n' + results[0].formatted_address});// this is display in tool tip/ icon color
                                   if (type=='E')  {marker.setIcon('http://maps.google.com/mapfiles/ms/icons/green-dot.png')};
                                   if (type=='L')  {marker.setIcon('http://maps.google.com/mapfiles/kml/pal4/icon53.png')};
                                   if (type=='S')  {marker.setIcon('http://maps.google.com/mapfiles/ms/icons/blue-dot.png')};
                            }
                           else {
                                console.log('No results found: ' + status);
                            }
                        }
                        return geocodeCallBack;
                    }
                } else 
               {
                    console.log('Failed to instantiate Google Geocoder object');
                }

                function updateProgressBar(percentage_factor) {
                    var map_canvas = document.getElementById('map_canvas');
                    var node = document.getElementById('progress_bar');
                    var w = map_canvas.style.width.match(/\d+/);
                    w = w * percentage_factor;
                    node.style.width = parseInt(w) + 'px';
                    if (percentage_factor == 1) {
                        // jscript style properties are different to the CSS style properties...
                        node.style.backgroundColor = 'green';
                    }
                }

            })();

        });

        </script>
    </head>
    <body>
    <div style='border: 1px solid black; width:1366px; height:3px;'>
        <div id='progress_bar' style='height:3px; width:0px; background-color:red;'/>
    </div>
    <!-- if you change this id, then also update code of progress bar above -->
        <div id='map_canvas' style='width:1900px; height:1000px;'></div>
    </body>
</html>
于 2014-02-21T03:15:29.007 回答