我在随机时间创建了几个CSV文件,其中包含客户端地址(少于3000个)。我可以将它发送到谷歌地图引擎来生成地图视图吗? (尝试自动化而不是丢弃文件)谢谢
答案 0 :(得分:0)
您可以将Maps Engine API用于insert rows to an existing table或upload data files (CSV, KML, shape files) to a new table。
此处唯一的问题是API仅支持核心“Maps Engine”产品,而不是Lite或Pro产品。如果您想进行试验,可以使用直线Maps Engine产品的免费等级。
答案 1 :(得分:0)
我的要求很简单,找到了解决问题的简单方法。刚刚在运行时生成一个HTML页面,所有文本地址都插入到JavaScript数组中,然后循环遍历它以生成地理编码和标记的地方。唯一的缺点是性能,因为Google要求连续的地理编码请求,间隔为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>