The geocodeing service is used to geocode an address EMS.Service.Geocode.geocode or to find the closest address to a given location EMS.Service.Geocode.reverse.
Both calls to geocode and reverse geocode use callbacks (see below).
function(response, status) {
}| response | {Object} is a wrapper around the results with some meta data about to the pagination information. |
| status | {EMS.Status} is the response status. Any other response other than EMS.Status.OK indicates some sort of error. You can consult the response.message for more information. |
{
results[]: {EMS.Geocode} // An array of results, this maybe empty if none were found
keywords: {String}, // If the query given was a string, these are left over words not used
// in the geocoding
pagination: {
total: {Integer}, // Total number of results available
start: {Integer} // Starting index of this result set
},
message: {String} // Only set in the case of a non EMS.Status.OK status
}| EMS. | The geocodeing service is used to geocode an address EMS.Service.Geocode.geocode or to find the closest address to a given location EMS.Service.Geocode.reverse. |
| Constructor | |
| EMS. | |
| Functions | |
| reverse | |
| geocode |
reverse: function( query, callback )
var service = new EMS.Service.Gecode();
service.reverse({"lon": 144.2232, "lat": -37.54883}, function(response, status) {
if (status == EMS.Status.OK) {
// Successful
for (var i = 0; i < response.results.length; i++) {
// Do something with the geocode
var geocode = response.results[i];
}
} else {
// Error status
alert(response.message);
}
});var point = new EMS.LonLat("lon": 144.2232, "lat": -37.54883);
var query = {
location: point,
radius: 10000, // 10 kilometre radius
granularity: [EMS.Granularity.STREET], // Only looking for streets
size: 2 // Maximum of 2 items to be returned
}
var service = new EMS.Service.Gecode();
service.reverse(query, function(response, status) {
if (status == EMS.Status.OK) {
// Successful
for (var i = 0; i < response.results.length; i++) {
// Do something with the geocode
var geocode = response.results[i];
}
} else {
// Error status
alert(response.message);
}
});| query | {Mixed} can be a EMS.LonLat or an {Object} which has a lon and lat property or a more complicated query with a location (has a lon and lat), size, radius and granularity array. |
| callback | {Function} the result callback. |
geocode: function( query, callback )
var service = new EMS.Service.Geocode();
service.geocode("Melbourne, VIC", function(response, status) {
if (status == EMS.Status.OK) {
// Successful
for (var i = 0; i < response.results.length; i++) {
// Do something with the geocode
var geocode = response.results[i];
}
} else {
// Error status
alert(response.message);
}
});var address = {
number: "222",
street: {
name: "Lonsdale",
type: "St"
}
suburb: "Melbourne",
state: "VIC",
postcode: "3000"
}
var service = new EMS.Service.Geocode();
service.geocode(address, function(response, status) {
if (status == EMS.Status.OK) {
// Successful
for (var i = 0; i < response.results.length; i++) {
// Do something with the geocode
var geocode = response.results[i];
}
} else {
// Error status
alert(response.message);
}
});var query = {
address: "222 Lonsdale St, Melbourne, VIC"
location: {"lon": 144.2232, "lat": -37.54883},
bounds: {"left": 142.2356, "top": -35.8993, "right": 142.78673, "bottom": -36.197883}
}
var service = new EMS.Service.Geocode();
service.geocode(query, function(response, status) {
if (status == EMS.Status.OK) {
// Successful
for (var i = 0; i < response.results.length; i++) {
// Do something with the geocode
var geocode = response.results[i];
}
} else {
// Error status
alert(response.message);
}
});| query | {Mixed} is either the address as a {String} or an {Object} which contains the address. |
| callback | {Function} is the callback function in the form function(result, status). |
geocode: function( query, callback )
reverse: function( query, callback )