Domanda

I have few CSV files created at random times with client addresses (less then 3000) on it. Can I send it to Google maps-engine to generate map-view? (trying to automate rather than dag-drop the file) Thanks

È stato utile?

Soluzione

You can use the Maps Engine API to either insert rows to an existing table or upload data files (CSV, KML, shape files) to a new table.

The only catch here is that the API is only supported on the core "Maps Engine" product, not the Lite or Pro products. There is a free tier of the straight Maps Engine product if you want to experiment.

Altri suggerimenti

My requirement was simple and found a simple way to solve it. Just generated a HTML page at run-time with all the text addresses inserted into a JavaScript array and then looped through it to generate places geocoded and marked. Only drawback was the performance, that happened because Google requires consecutive geocoding requests with some 1 sec interval. I used VBA code to generate the the 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>
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top