
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-22-2015 12:51 AM
Hello All,
I want to calculate distance on the basis of two postcodes of UK. Is there any API present for it.
Also, how can I call custom APIs in Service Now. In Postcodes.io lot of APIs are present but I don't know how to use them in Service Now. Any ideas?
Regards/Chandresh
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-24-2015 02:39 AM
What about the following? You could add the "Location" reference field to tickets and "Current Location" reference field to Users. You would then define Postcodes as Locations, which have longitude and latitude information OOB. If you activate the GeoLocations plugin, it should even populate the long/lat values automatically from the postcodes. If they don't, you should write your own Business Rule script to populate the coordinates.
Once you have the coordinates filled in, you could create a new "Tickets nearby" module for your users, which is a list of records on the Incident table (or whatever table your tickets are in). The module would have a filter that would measure the distance between the Ticket's location and the User's current location. This functionality can be found in GeoLocations as well, as the Script Include called GeolocationUtils, which has the GeolocationUtils prototype with the function "getTwoPointsDistance: function(p1Lat, p1Long, p2Lat, p2Long)".
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-24-2015 02:39 AM
What about the following? You could add the "Location" reference field to tickets and "Current Location" reference field to Users. You would then define Postcodes as Locations, which have longitude and latitude information OOB. If you activate the GeoLocations plugin, it should even populate the long/lat values automatically from the postcodes. If they don't, you should write your own Business Rule script to populate the coordinates.
Once you have the coordinates filled in, you could create a new "Tickets nearby" module for your users, which is a list of records on the Incident table (or whatever table your tickets are in). The module would have a filter that would measure the distance between the Ticket's location and the User's current location. This functionality can be found in GeoLocations as well, as the Script Include called GeolocationUtils, which has the GeolocationUtils prototype with the function "getTwoPointsDistance: function(p1Lat, p1Long, p2Lat, p2Long)".

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-28-2015 03:24 AM
Hi Peter,
Thank you so much, it worked like magic. however, there are little difference between distance calculated by the Geolocation plugin and distance calculated by Google Map. I believe it might be because in Service Now we are calculating the distance by below formula and Google Map use navigation/GPS satellite technology. Do you have any idea about this?
getTwoPointsDistance: function(p1Lat, p1Long, p2Lat, p2Long){
var R = 6371; // Radius of the Earth in km
var dLat = (p2Lat - p1Lat) * Math.PI / 180;
var dLon = (p2Long - p1Long) * Math.PI / 180;
var a = Math.sin(dLat / 2) * Math.sin(dLat / 2) +
Math.cos(p1Lat * Math.PI / 180) * Math.cos(p2Lat * Math.PI / 180) *
Math.sin(dLon / 2) * Math.sin(dLon / 2);
var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
var d = R * c;
return d; // returns the distance between p1 and p2 in kilometer
},
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-28-2015 03:53 AM
It seems the GeoLocation plugin uses the Haversine formula to calculate the distance between two points as explained here. If you want to calculate the actual routed distance, you have to script it yourself and use the DistanceMatrixService from the Google Maps Javascript API. The DistanceMatrixResponseElement contains a distance field with the information as explained on stackoverflow http://stackoverflow.com/a/2472669/1410402. Sample code from Google can be found on their website Distance Matrix service Sample.
I don't know how popular your SN Instance is, but keep in mind that there are Google API limitations as explained here, JavaScript API Usage Limits.
Below is a quote of Google's JavaScript API Usage Limits:
Users of the standard API:
| Enable pay-as-you-go billing to unlock higher quotas: After exceeding the free usage limits, billing at $0.50 USD / 1000 additional requests, up to 1,000,000 per 24 hours. |