diff --git a/dist/geocoder.js b/dist/geocoder.js index 610eb66..291ef31 100644 --- a/dist/geocoder.js +++ b/dist/geocoder.js @@ -1 +1 @@ -if(function(){"use strict";var a={};a.version="0.0.0",a.createGeocoder=function(b){var c=new a.ProviderFactory;return c.createProvider(b)};var b="object"==typeof window?window:"object"==typeof exports?exports:{};b.GeocoderJS=a}(),"function"==typeof define&&define.amd&&define(GeocoderJS),"undefined"==typeof GeocoderJS&&"function"==typeof require)var GeocoderJS=require("../GeocoderJS.js");if(function(a){"use strict";a.ProviderBase=function(){},a.ProviderBase.prototype={geocode:function(){},geodecode:function(){},mapToGeocoded:function(){},executeRequest:function(){}}}(GeocoderJS),"undefined"==typeof GeocoderJS&&"function"==typeof require)var GeocoderJS=require("./GeocoderJS.js");if(function(a){"use strict";a.Geocoded=function(){},a.Geocoded.prototype={getCoordinates:function(){return[this.latitude,this.longitude]},getLatitude:function(){return this.latitude},getLongitude:function(){return this.longitude},getBounds:function(){},getStreetNumber:function(){return this.streetNumber},getStreetName:function(){return this.streetName},getCity:function(){return this.city},getZipcode:function(){return this.postal_code},getCityDistrict:function(){},getCounty:function(){},getCountyCode:function(){},getRegion:function(){return this.region}}}(GeocoderJS),"undefined"==typeof GeocoderJS&&"function"==typeof require)var GeocoderJS=require("./GeocoderJS.js");if(function(a){"use strict";var b={type:"Feature",properties:{},geometry:{type:"Point",coordinates:[]}};a.GeoJSONDumper=function(){return{dump:function(a){var c=b;return c.geometry.coordinates=[a.getLongitude(),a.getLatitude()],c}}}}(GeocoderJS),"undefined"==typeof GeocoderJS&&"function"==typeof require){var GeocoderJS=require("../GeocoderJS.js");require("../ExternalURILoader.js")}if(function(a){"use strict";a.ProviderFactory=function(){},a.ProviderFactory.prototype.createProvider=function(b){"string"==typeof b&&(b={provider:b});var c,d=new a.ExternalURILoader;switch(b.provider){case"google":c=new a.GoogleAPIProvider(b);break;case"mapquest":c=new a.MapquestProvider(b);break;case"openstreetmap":c=new a.OpenStreetMapProvider(d,b)}return c}}(GeocoderJS),"undefined"==typeof GeocoderJS&&"function"==typeof require)var GeocoderJS=require("../GeocoderJS.js");if(function(a){"use strict";var b=!1;a.ExternalURILoader=function(a){this.options={},void 0===a&&(a={}),this.setOptions(a)},a.ExternalURILoader.prototype.setOptions=function(a){var b={protocol:null,host:null,pathname:null};for(var c in b)this.options[c]=void 0!==a[c]?a[c]:b[c]},a.ExternalURILoader.prototype.executeRequest=function(c,d){function e(c,d){var e,f=require("url"),h=b?require("https"):require("http"),i={protocol:b?"https":"http",host:g.options.host,pathname:g.options.pathname,query:c};i.query.sensor="false",e=f.format(i),h.get(e,function(b){if(200!=b.statusCode)throw"Received HTTP status code "+b.statusCode+" when attempting geocoding request.";b.data="",b.setEncoding("utf8"),b.on("data",function(a){b.data+=a}),b.on("end",function(){if(!b.data||!b.data.length)throw"Received empty data when attempting geocoding request.";var c=!1,e=0,f=[];try{c=JSON.parse(b.data)}catch(g){throw"Received invalid JSON data when attempting geocoding request."}if(c&&c.status){if("OVER_QUERY_LIMIT"===c.status)throw"Exceeded daily quota when attempting geocoding request.";if("OK"===c.status&&c.results){for(;e + + + Geocoder.js: Bing Example + + + + + + + + \ No newline at end of file diff --git a/src/GeocoderProviderFactory.js b/src/GeocoderProviderFactory.js index f2b6629..f7b475d 100644 --- a/src/GeocoderProviderFactory.js +++ b/src/GeocoderProviderFactory.js @@ -38,6 +38,9 @@ if (typeof GeocoderJS === "undefined" && typeof require === "function") { case 'openstreetmap': provider = new GeocoderJS.OpenStreetMapProvider(externalLoader, options); break; + case 'bing': + provider = new GeocoderJS.BingProvider(externalLoader, options); + break; } return provider; diff --git a/src/providers/BingProvider.js b/src/providers/BingProvider.js new file mode 100644 index 0000000..78e957e --- /dev/null +++ b/src/providers/BingProvider.js @@ -0,0 +1,87 @@ +if (typeof GeocoderJS === "undefined" && typeof require === "function") { + var GeocoderJS = require("../GeocoderJS.js"); + require("../Geocoded.js"); + require("../ExternalURILoader.js"); + require("../providers/ProviderBase.js"); +} + +;(function (GeocoderJS) { + "use strict"; + + GeocoderJS.BingProvider = function(_externalLoader, options) { + GeocoderJS.BingProvider.prototype = new GeocoderJS.ProviderBase(); + GeocoderJS.BingProvider.prototype.constructor = GeocoderJS.BingProvider; + + if (_externalLoader === undefined) { + throw "No external loader defined."; + } + this.externalLoader = _externalLoader; + + console.log(options); + this.apiKey = options.apiKey; + }; + + GeocoderJS.BingProvider.prototype.geocode = function(searchString, callback) { + this.externalLoader.setOptions({ + protocol: 'http', + host: 'dev.virtualearth.net', + pathname: 'REST/v1/Locations' + }); + + var params = { + q: searchString, + key: this.apiKey + }; + + this.executeRequest(params, callback); + }; + + GeocoderJS.BingProvider.prototype.geodecode = function(latitude, longitude, callback) { + this.externalLoader.setOptions({ + protocol: 'http', + host: 'dev.virtualearth.net', + pathname: 'REST/v1/Locations/point' + }); + + var params = { + point: latitude + ', ' + longitude, + key: this.apiKey + }; + + var _this = this; + + this.externalLoader.executeRequest(params, function(data) { + var results = []; + results.push(_this.mapToGeocoded(data)); + callback(results); + }); + }; + + GeocoderJS.BingProvider.prototype.executeRequest = function(params, callback) { + var _this = this; + + this.externalLoader.executeRequest(params, function(data) { + var results = []; + for (var i in data) { + results.push(_this.mapToGeocoded(data[i])); + } + callback(results); + }); + }; + + GeocoderJS.BingProvider.prototype.mapToGeocoded = function(result) { + var geocoded = new GeocoderJS.Geocoded(); + + geocoded.latitude = result.lat * 1; + geocoded.longitude = result.lon * 1; + + geocoded.streetNumber = (result.address.house_number !== undefined) ? result.address.house_number : undefined; + geocoded.streetName = result.address.road; + geocoded.city = result.address.city; + geocoded.region = result.address.state; + geocoded.postal_code = result.address.postcode; + + return geocoded; + }; + +})(GeocoderJS); pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy