<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyDaDeRq_2VLef8PV_kTx8qFYAaBESl2v_M&libraries=geometry"></script>
<div id="tool_container">
<h3>Find the nearest location from a list of addresses</h3>
<p>Add a list of addresses, one address per line, set what items you would like to display, and click go!</p>
<div id="tool_settings">
<p class="setting_toggle">
<label>The number of closest chargers to output.</label>
<input id="number_of_results" class="tool_setting" type="number" name="number_of_results" value="1" min="1" max="10">
<small>(The free daily limit is 2,500, so if the number of addresses times the number of requests is over that, you will incur charges)</small>
</p>
<p class="setting_toggle">
<label>Max number of miles for the charger (leave blank for no limit).</label>
<input id="max_driving_distance" class="tool_setting" type="number" name="max_driving_distance" value="15" min="1" max="100">
<small>(Always Outputs the first result. Displays a flag if it is over the limit. Subsequent results get suppressed if over the limit.)</small>
</p>
<div class="setting_toggle">
<input id="table_headers" class="tool_setting" type="checkbox" name="table_headers" value="table_headers" checked="checked"> Output table headers
</div>
<div class="setting_toggle">
<input id="working_chargers_only" class="tool_setting" type="checkbox" name="working_chargers_only" value="working_chargers_only" checked="checked"> Show only working chargers
</div>
<div class="setting_toggle">
<input id="fast_chargers_only" class="tool_setting" type="checkbox" name="fast_chargers_only" value="fast_chargers_only" checked="checked"> Show only fast chargers
</div>
<p class="setting_toggle">
<label>The size of the static map of the charger you would like. (The format shouls be [width]x[height] in pixels with no...
jQuery(document).ready(function(){
var addresses;
var progress_status;
var charger_data;
var promises = [];
var number_of_results;
var geocoder;
// Google has a max of 50 request per second. However, it seems to fire much more often.
// Delay is 1000 ms x the number of results. ( 20 ms is exact for 50 per second. Changed to 50 times to avoid more issues. )
var delay;
var max_driving_distance;
jQuery('#submit_btn').on('click', function(){
// get lines from input field.
addresses = [];
var lines = jQuery('#addresses').val().split(/\n/);
for (var i=0; i < lines.length; i++) {
// only push this line if it contains a non whitespace character.
if (/\S/.test(lines[i])) {
addresses.push({ address: jQuery.trim(lines[i]), geo: { latitude: 0, longitude: 0 }, nearest: [], errors: [] });
}
}
number_of_results = parseInt( $('#number_of_results').val() );
progress_status = { done:0, error:0, total: addresses.length };
delay = 5000 * number_of_results;
// Initialize Error Messages.
jQuery('#error_message').html('');
if ( progress_status.total * number_of_results > 2499 ){
display_error( 'Processing ' + progress_status.total + ' records. Google has a max of 2,500 per day. You may incur charges.</p>' );
} else {
display_error( 'Processing ' + progress_status.total + ' records.</p>' );
}
//display loading bar
jQuery('#loading').fadeIn(100).find('#loading_bar').css('width', '2%');
jQuery("#progress").html(progress_status.done + '/' + progress_status.total );
jQuery('#csv_result').val('Processing...');
max_driving_distance = parseInt( $('#max_driving_distance').val() );
// Create ajax request parameters
$.ajax({
method: "GET",
url: "https://api11.evgo.com/stations/mapsites/callback/getMapData", // get API data
jsonpCallback: 'getMapData',
dataType: "jsonp",
data: {
dl: 1 // Only for dropbox link. Remove when move to actual charger_data
},
}).done(function( data ) {
var...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Fiddle Pages
Your fiddles accessible under a custom domain and a vanity path - the simplest hosting for your personal project.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Get Fiddle Pages with PRO
Your fiddles accessible under a custom domain and a vanity path - the simplest hosting for your personal project.