Skip to content

Instantly share code, notes, and snippets.

@tarolandia tarolandia/geocoder.js
Last active Dec 29, 2015

Embed
What would you like to do?
Mock maps API or at least part of it
(function() {
var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
(function() {
window.google = {};
window.google.maps = {};
window.google.maps.GeocoderStatus = {};
window.google.maps.GeocoderStatus.OK = "OK";
window.google.maps.MapTypeId = {};
window.google.maps.MapTypeId.ROADMAP = "roadmap";
window.google.maps.Map = function(id,options) { return true; };
window.google.maps.Marker = function(options) { return true; };
window.google.maps.event = {};
window.google.maps.event.addListener = function(map, evt, callback) { return true; };
window.google.maps.LatLng = function(latitude, longitude) {
this.ob = latitude;
this.pb = longitude;
this.lat = function() { return latitude; };
this.lng = function() { return longitude; };
};
return google.maps.Geocoder = function() {
var _this = this;
this.geocode = function(params, success) {
var response = {};
if (params.latLng !== undefined) {
var address = "Charcas 3734, Ciudad Autónoma de Buenos Aires, Buenos Aires, Argentina";
response = _this.mock_response(address);
success(response.results, response.status);
}
if (params.address !== undefined) {
response = _this.mock_response(params.address);
success(response.results, response.status);
}
};
this.mock_response = function(full_addr) {
var parts = full_addr.split(', ');
var addr = {
street_number: parts[0].split(" ")[1],
street: parts[0].split(" ")[0],
locality: "",
city: parts[1],
state: parts[2],
country: parts[3],
country_code: 'AR',
zip: '123123123CB',
lat: 37.42291810,
lng: -122.08542120,
formatted_address: full_addr
};
return {
results: [
{
address_components: [
{
long_name: addr.street_number,
short_name: addr.street_number,
types: [ "street_number" ]
},
{
long_name: addr.street,
short_name: addr.street,
types: [ "route" ]
},
{
long_name: addr.locality,
short_name: addr.locality,
types: [ "locality", "political" ]
},
{
long_name: addr.city,
short_name: addr.city,
types: [ "administrative_area_level_2", "political" ]
},
{
long_name: addr.state,
short_name: addr.state,
types: [ "administrative_area_level_1", "political" ]
},
{
long_name: addr.country,
short_name: addr.country_code,
types: [ "country", "political" ]
},
{
long_name: addr.zip,
short_name: addr.zip,
types: [ "postal_code" ]
}
],
formatted_address: addr.formatted_address,
geometry: {
'location': {
lat: function() { return addr.lat; },
lng: function() { return addr.lng; }
},
location_type: "ROOFTOP",
viewport: {
northwest: {
lat: addr.lat,
lng: addr.lng
},
southwest: {
lat: addr.lat,
lng: addr.lng
}
}
},
types: ["street_address"]
}
],
status: "OK"
};
};
};
})();
}).call(this);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.