Store Finder Example
Source Code
<script type="text/javascript" src="http://loki.com/plugin/files/loki.js"></script>
<script type="text/javascript">
//<![CDATA[
var map;
function init() {
// Setup the GMap instance
map = new GMap2(document.getElementById("map"));
map.setCenter(new GLatLng(42.364632, -71.058368), 13);
// and kick off the Loki request
requestLocation();
}
function requestLocation() {
var loki = new LokiAPI();
loki.onSuccess = function(location) {
// Populate form input fields
document.getElementById("address").value = location.house_number+' '+location.street;
document.getElementById("city").value = location.city;
document.getElementById("region_code").value = location.region_code;
document.getElementById("postal_code").value = location.postal_code;
// Reset the center of the map and place a new marker
var point = new GLatLng(parseFloat(location.latitude), parseFloat(location.longitude));
map.setCenter(point, 13);
var marker = new GMarker(point);
map.addOverlay(marker);
marker.openInfoWindowHtml('<strong>Your location</strong><br/>'+location.latitude+', '+location.longitude+'');
};
loki.onFailure = function(error, msg){
alert('An error has been encountered ('+error+'). '+msg);
};
loki.setKey("loki.com");
// Here we want the entire location object returned -- lat/lon and full reverse geocode
loki.requestLocation(true,loki.FULL_STREET_ADDRESS_LOOKUP);
}
window.onload = init;
//]]>
</script>