VC4A API JavaScript Client Demo
A minimal client illustrating how to retrieve JSON data from the RESTful VC4A web API and plot results on a map.
by Bill Zimmerman
HTML
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script>
<script src="https://maps.google.com/maps/api/js?sensor=true"></script>
<link rel="stylesheet" href="https://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/gmaps.js/0.4.19/gmaps.js"></script>
<title>VC4A API Client Demo</title>
<body>
<div class="navbar">
<div class="navbar-inner"> <a class="brand" href="#">VC4A API JavaScript Client Demo</a>
</div>
</div>
<div id="main" class="container">
<div id="content">
<h1>Mobile ventures in Nigeria</h1>
<div id="map"></div>
<h3>Rest API Call</h3>
<pre>dataType: JSON</pre>
<pre>HTTP method: GET /v1/ventures/search.json?country=nigeria&sector=mobile&limit=100</pre><br />
</div>
</div>
CSS
#map {
width:600px;
height:500px;
}
JavaScript
$(document).ready(function () {
var map = new GMaps({
div: '#map',
lat: 9.072264,
lng: 7.491302,
zoom: 6
});
$.ajax({
dataType: "json",
url: "https://api.vc4africa.biz/v1/ventures/search.json?country=nigeria§or=mobile&limit=100",
type: "GET",
success: function (data) {
//console.log(data);
$.each(data, function () {
$.each(this, function () {
if (typeof this.latitude != 'undefined' && typeof this.longitude != 'undefined') {
map.addMarker({
lat: this.latitude,
lng: this.longitude,
infoWindow: {
content: this.title
}
})
}
});
});
},
error: function (xhr, ajaxOptions, thrownError) {
alert(xhr.status);
alert(thrownError);
}
});
});