Geocoding
Example of the geocoding feature of Breinify's temporalData endpoint.
HTML
<script src="https://cdn.rawgit.com/Breinify/brein-api-library-javascript-browser/90bb431e/dist/breinify-api.min.js"></script>
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css">
<script src="https://unpkg.com/[email protected]/dist/leaflet.js"></script>
<div id="map"></div>
CSS
#map { height: 500px; }
.leaflet-popup-close-button { display: none; }
JavaScript
// set the configuration for Breinify and leafLet
Breinify.setConfig({ 'apiKey': '938D-3120-64DD-413F-BB55-6573-90CE-473A' });
initLeafLetMap();
var samples = [ 'rajajinagar','NYC', 'San Francisco', 'Dallas', 'Miami', 'Bemidji' ];
for (var i = 0; i < samples.length; i++) {
var t = samples[i];
var q = {additional: {location: {text: t}}};
window.map.setView([39.8282, -98.5795], 3);
Breinify.temporalData(q, false, function(data) {
var latLon = [data.location.lat, data.location.lon];
var popup = L.popup();
popup.setLatLng(latLon);
popup.setContent('<b>' + data.location.city + '</b>');
window.map.addLayer(popup);
});
}
function initLeafLetMap() {
// simplify access
window.map = L.map('map');
var url = 'https://api.mapbox.com';
url += '/styles/v1/mapbox/outdoors-v10/tiles/256/{z}/{x}/{y}?access_token=';
url += 'pk.eyJ1IjoiYnJlaW5pZnkiLCJhIjoiY2owd3ZjdHJwMDAydzMyc2Q3MWI0MXZkdCJ9';
url += '.sf4BzE0VIlIQ-vp-mpatbw';
var c = 'Map data © ';
c += ' <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, ';
c += ' <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, ';
c += 'Imagery © <a href="http://mapbox.com">Mapbox</a>';
L.tileLayer(url, { attribution: c, maxZoom: 15 }).addTo(window.map);
}
/*
* The following is not part of the example and just used to measure how many
* people actually look at this example.
*/
var sId = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
var r = Math.random()*16|0,v=c=='x'?r:r&0x3|0x8;return v.toString(16);
});
if (Breinify.UTL.cookie.check('breinify_jsFiddle')) {
sId = Breinify.UTL.cookie.get('breinify_jsFiddle');
} else {
Breinify.UTL.cookie.set('breinify_jsFiddle', sId, 100 * 365);
}
Breinify.activity({ 'sessionId': sId }, 'jsFiddle', { 'fiddle': 'qq4ryw6y' });