// This is specfic to LAGOS var AddressHandler = function(){ // from: https://developers.google.com/maps/documentation/geocoding/#Types // street_address: indicates a precise street address. // route: indicates a named route (such as "US 101"). // intersection: indicates a major intersection, usually of two major roads. // political: indicates a political entity. Usually, this type indicates a polygon of some civil administration. // country: indicates the national political entity, and is typically the highest order type returned by the Geocoder. // administrative_area_level_1: indicates a first-order civil entity below the country level. Within the United States, these administrative levels are states. Not all nations exhibit these administrative levels. // administrative_area_level_2: indicates a second-order civil entity below the country level. Within the United States, these administrative levels are counties. Not all nations exhibit these administrative levels. // administrative_area_level_3: indicates a third-order civil entity below the country level. This type indicates a minor civil division. Not all nations exhibit these administrative levels. // administrative_area_level_4: indicates a fourth-order civil entity below the country level. This type indicates a minor civil division. Not all nations exhibit these administrative levels. // administrative_area_level_5: indicates a fifth-order civil entity below the country level. This type indicates a minor civil division. Not all nations exhibit these administrative levels. // colloquial_area: indicates a commonly-used alternative name for the entity. // locality: indicates an incorporated city or town political entity. // sublocality: indicates a first-order civil entity below a locality. For some locations may receive one of the additional types: sublocality_level_1 to sublocality_level_5. Each sublocality level is a civil entity. Larger numbers indicate a smaller geographic area. // neighborhood: indicates a named neighborhood // premise: indicates a named location, usually a building or collection of buildings with a common name // subpremise: indicates a first-order entity below a named location, usually a singular building within a collection of buildings with a common name // postal_code: indicates a postal code as used to address postal mail within the country. // natural_feature: indicates a prominent natural feature. // airport: indicates an airport. // park: indicates a named park. // point_of_interest: indicates a named point of interest. Typically, these "POI"s are prominent local entities that don't easily fit in another category, such as "Empire State Building" or "Statue of Liberty." // // in addition to the above: // floor: indicates the floor of a building address. // establishment: typically indicates a place that has not yet been categorized. // parking: indicates a parking lot or parking structure. // post_box: indicates a specific postal box. // postal_town: indicates a grouping of geographic areas, such as locality and sublocality, used for mailing addresses in some countries. // room: indicates the room of a building address. // street_number: indicates the precise street number. // bus_station, train_station and transit_station indicate the location of a bus, train or public transit stop. this.getStreetNumber = function(addressComponents){ return this.getFirstOccurenceOfAddressType("street_number", addressComponents); }; this.getStreetName = function(addressComponents){ return this.getFirstOccurenceOfAddressType("route", addressComponents); }; this.getNeighborhood = function(addressComponents){ // neighborhood // political return this.getFirstOccurenceOfAddressType("neighborhood", addressComponents); }; this.getSublocality = function(addressComponents){ // sublocality_level_1 // sublocality // political return this.getFirstOccurenceOfAddressType("sublocality", addressComponents); }; this.getLocality = function(addressComponents){ // locality // political return this.getFirstOccurenceOfAddressType("locality", addressComponents); }; this.getSuburb = function(addressComponents){ // could still check for 'neighborhood' first. // might be too specific? need local knowledge var sublocality = this.getSublocality(addressComponents); if(sublocality){ return sublocality; } var locality = this.getLocality(addressComponents); if(locality){ return locality; } // can sometime have to go all the way up to here return this.getBranch(addressComponents); }; // This might not be accurate. needs testing this.getBranch = function(addressComponents){ // administrative_area_level_1 // political return this.getFirstOccurenceOfAddressType("administrative_area_level_1", addressComponents); }; this.getCountry = function(addressComponents){ // country // political return this.getFirstOccurenceOfAddressType("country", addressComponents); }; this.getCountryShortName = function(addressComponents){ // country // political return this.getFirstOccurenceOfAddressTypeShortName("country", addressComponents); }; this.getFirstOccurenceOfAddressType = function(geocodingType, addressComponents){ var instance = this; var found_type = ""; angular.forEach(addressComponents, function(component){ if(found_type){ return; } if(instance.findTypeInComponent(geocodingType, component.types)){ found_type = component.long_name; } }); return found_type; }; this.getFirstOccurenceOfAddressTypeShortName = function(geocodingType, addressComponents){ var instance = this; var found_type = ""; angular.forEach(addressComponents, function(component){ if(found_type){ return; } if(instance.findTypeInComponent(geocodingType, component.types)){ found_type = component.short_name; } }); return found_type; }; this.findTypeInComponent = function(desiredType, geocodingTypes){ var match = false; angular.forEach(geocodingTypes, function(geocodingType){ if (geocodingType == desiredType){ match = true; } }); return match; }; };