summaryrefslogtreecommitdiff
path: root/plugins/Mapstraction/js/mxn.google.geocoder.js
diff options
context:
space:
mode:
authorZach Copley <zach@status.net>2009-11-19 20:12:46 -0800
committerZach Copley <zach@status.net>2009-11-19 20:12:46 -0800
commit4b98edf75f4e255f8c61087bd1525d89653a521f (patch)
treeb2a7eb6d77429eadb1beabe2d5e6ae1c1a2831d6 /plugins/Mapstraction/js/mxn.google.geocoder.js
parentf92574dbcb1f2d7cd0aaf3c9362db46fa066e888 (diff)
parentc213477081afefb1720c8ae729d1965e7a1dac63 (diff)
Merge branch '0.9-release'
* 0.9-release: (874 commits) Removed call to NewDirectMessage() until IE return is fixed i.e., Don't show flag user button your own profile Fixed HXR response for flag user Using the right form class name Using common_redirect Left a form_data class of a <ul> in the user admin panel Added validation to fields in user admin panel Added a user admin panel Added mobile logos for default and identica themes Changed gif to png Changed this to action. THANKS zach! Doing content negotiation only once Add execute bit to pingqueuehandler Localisation updates for !StatusNet from !translatewiki.net Use the browser's geolocation API to set the location on the notice form Add geometa library, and include it. Add location form elements to the noticeform, and save their values on submission Use the $user object nickname, as login name doesnt have to == nickname anymore with plugins such as ldap/etc Revert "Re added NICKNAME_FMT constant to router.php." Moved most path and server settings to a new paths admin panel ... Conflicts: js/util.js locale/it_IT/LC_MESSAGES/statusnet.mo locale/mk_MK/LC_MESSAGES/statusnet.mo locale/mk_MK/LC_MESSAGES/statusnet.po locale/pt_BR/LC_MESSAGES/statusnet.mo locale/vi_VN/LC_MESSAGES/statusnet.mo plugins/InfiniteScroll/infinitescroll.js plugins/Realtime/realtimeupdate.js
Diffstat (limited to 'plugins/Mapstraction/js/mxn.google.geocoder.js')
-rw-r--r--plugins/Mapstraction/js/mxn.google.geocoder.js179
1 files changed, 179 insertions, 0 deletions
diff --git a/plugins/Mapstraction/js/mxn.google.geocoder.js b/plugins/Mapstraction/js/mxn.google.geocoder.js
new file mode 100644
index 000000000..5119c00a1
--- /dev/null
+++ b/plugins/Mapstraction/js/mxn.google.geocoder.js
@@ -0,0 +1,179 @@
+/*
+ Copyright (c) 2007, Andrew Turner
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
+ * Neither the name of the Mapstraction nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+
+// Use http://jsdoc.sourceforge.net/ to generate documentation
+
+// TODO: add reverse geocoding support
+
+/**
+ * MapstractionGeocoder instantiates a geocoder with some API choice
+ * @param {Function} callback The function to call when a geocode request returns (function(waypoint))
+ * @param {String} api The API to use, currently only 'mapquest' is supported
+ * @param {Function} error_callback The optional function to call when a geocode request fails
+ * @constructor
+ */
+function MapstractionGeocoder(callback, api, error_callback) {
+ this.api = api;
+ this.callback = callback;
+ this.geocoders = new Object();
+ if(error_callback == null) {
+ this.error_callback = this.geocode_error
+ } else {
+ this.error_callback = error_callback;
+ }
+
+ // This is so that it is easy to tell which revision of this file
+ // has been copied into other projects.
+ this.svn_revision_string = '$Revision: 107 $';
+
+ this.addAPI(api);
+
+}
+
+
+/**
+ * Internal function to actually set the router specific parameters
+ */
+MapstractionGeocoder.prototype.addAPI = function(api) {
+
+ me = this;
+ switch (api) {
+ case 'google':
+ this.geocoders[api] = new GClientGeocoder();
+ break;
+ case 'mapquest':
+ //set up the connection to the geocode server
+ var proxyServerName = "";
+ var proxyServerPort = "";
+ var ProxyServerPath = "mapquest_proxy/JSReqHandler.php";
+
+ var serverName = "geocode.access.mapquest.com";
+ var serverPort = "80";
+ var serverPath = "mq";
+ this.geocoders[api] = new MQExec(serverName, serverPath, serverPort, proxyServerName,
+ ProxyServerPath, proxyServerPort );
+
+ break;
+ default:
+ alert(api + ' not supported by mapstraction-geocoder');
+ }
+}
+/**
+ * Change the Routing API to use
+ * @param {String} api The API to swap to
+ */
+MapstractionGeocoder.prototype.swap = function(api) {
+ if (this.api == api) { return; }
+
+ this.api = api;
+ if (this.geocoders[this.api] == undefined) {
+ this.addAPI($(element),api);
+ }
+}
+
+/**
+ * Default Geocode error function
+ */
+MapstractionGeocoder.prototype.geocode_error = function(response) {
+ alert("Sorry, we were unable to geocode that address");
+}
+
+/**
+ * Default handler for geocode request completion
+ */
+MapstractionGeocoder.prototype.geocode_callback = function(response, mapstraction_geocoder) {
+ var return_location = new Object();
+
+ // TODO: what if the api is switched during a geocode request?
+ // TODO: provide an option error callback
+ switch (mapstraction_geocoder.api) {
+ case 'google':
+ if (!response || response.Status.code != 200) {
+ mapstraction_geocoder.error_callback(response);
+ } else {
+ return_location.street = "";
+ return_location.locality = "";
+ return_location.region = "";
+ return_location.country = "";
+
+ var place = response.Placemark[0];
+ if(place.AddressDetails.Country.AdministrativeArea != null) {
+ return_location.region = place.AddressDetails.Country.AdministrativeArea.AdministrativeAreaName;
+
+ if(place.AddressDetails.Country.AdministrativeArea.SubAdministrativeArea != null) {
+ if(place.AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.Locality != null) {
+ return_location.locality = place.AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.Locality.LocalityName;
+
+ if(place.AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.Locality.Thoroughfare != null)
+ return_location.street = place.AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.Locality.Thoroughfare.ThoroughfareName;
+ }
+
+ }
+
+ }
+ return_location.country = place.AddressDetails.Country.CountryNameCode;
+ return_location.address = place.address;
+
+ return_location.point = new mxn.LatLonPoint(place.Point.coordinates[1],
+ place.Point.coordinates[0]);
+ mapstraction_geocoder.callback(return_location);
+ }
+ break;
+ case 'mapquest':
+ break;
+ }
+}
+
+
+/**
+ * Performs a geocoding and then calls the specified callback function with the location
+ * @param {Object} address The address object to geocode
+ */
+ MapstractionGeocoder.prototype.geocode = function(address) {
+ var return_location = new Object();
+
+ // temporary variable for later using in function closure
+ var mapstraction_geocoder = this;
+
+ switch (this.api) {
+ case 'google':
+ if (address.address == null || address.address == "")
+ address.address = address.street + ", " + address.locality + ", " + address.region + ", " + address.country
+ this.geocoders[this.api].getLocations(address.address, function(response) { mapstraction_geocoder.geocode_callback(response, mapstraction_geocoder); });
+ break;
+ case 'mapquest':
+ var mqaddress = new MQAddress();
+ var gaCollection = new MQLocationCollection("MQGeoAddress");
+ //populate the address object with the information from the form
+ mqaddress.setStreet(address.street);
+ mqaddress.setCity(address.locality);
+ mqaddress.setState(address.region);
+ mqaddress.setPostalCode(address.postalcode);
+ mqaddress.setCountry(address.country);
+
+ this.geocoders[this.api].geocode(mqaddress, gaCollection);
+ var geoAddr = gaCollection.get(0);
+ var mqpoint = geoAddr.getMQLatLng();
+ return_location.street = geoAddr.getStreet();
+ return_location.locality = geoAddr.getCity();
+ return_location.region = geoAddr.getState();
+ return_location.country = geoAddr.getCountry();
+ return_location.point = new mxn.LatLonPoint(mqpoint.getLatitude(), mqpoint.getLongitude());
+ this.callback(return_location, this);
+ break;
+ default:
+ alert(api + ' not supported by mapstraction-geocoder');
+ break;
+ }
+ }