|
19 | 19 | location: _marker.position,
|
20 | 20 | radius: options.radius,
|
21 | 21 | locationName: options.locationName,
|
| 22 | + addressComponents: { |
| 23 | + formatted_address: null, |
| 24 | + addressLine1: null, |
| 25 | + addressLine2: null, |
| 26 | + streetName: null, |
| 27 | + streetNumber: null, |
| 28 | + city: null, |
| 29 | + state: null, |
| 30 | + stateOrProvince: null |
| 31 | + }, |
22 | 32 | settings: options.settings,
|
23 | 33 | domContainer: domElement,
|
24 | 34 | geodecoder: new google.maps.Geocoder()
|
|
72 | 82 | gMapContext.geodecoder.geocode({latLng: gMapContext.location}, function(results, status){
|
73 | 83 | if (status == google.maps.GeocoderStatus.OK && results.length > 0){
|
74 | 84 | gMapContext.locationName = results[0].formatted_address;
|
| 85 | + gMapContext.addressComponents = |
| 86 | + GmUtility.address_component_from_google_geocode(results[0].address_components); |
75 | 87 | }
|
76 | 88 | if (callback) {
|
77 | 89 | callback.call(this, gMapContext);
|
|
86 | 98 | },
|
87 | 99 | locationFromLatLng: function(lnlg) {
|
88 | 100 | return {latitude: lnlg.lat(), longitude: lnlg.lng()}
|
| 101 | + }, |
| 102 | + address_component_from_google_geocode: function(address_components) { |
| 103 | + var result = {}; |
| 104 | + for (var i = address_components.length; i>=0; i--) { |
| 105 | + var component = address_components[i]; |
| 106 | + // Postal code |
| 107 | + if (component.types.indexOf('postal_code') >= 0) { |
| 108 | + result.postalCode = component.short_name; |
| 109 | + } |
| 110 | + // Street number |
| 111 | + else if (component.types.indexOf('street_number') >= 0) { |
| 112 | + result.streetNumber = component.short_name; |
| 113 | + } |
| 114 | + // Street name |
| 115 | + else if (component.types.indexOf('route') >= 0) { |
| 116 | + result.streetName = component.short_name; |
| 117 | + } |
| 118 | + // City |
| 119 | + else if (component.types.indexOf('sublocality') >= 0) { |
| 120 | + result.city = component.short_name; |
| 121 | + } |
| 122 | + // State \ Province |
| 123 | + else if (component.types.indexOf('administrative_area_level_1') >= 0) { |
| 124 | + result.stateOrProvince = component.short_name; |
| 125 | + } |
| 126 | + // State \ Province |
| 127 | + else if (component.types.indexOf('country') >= 0) { |
| 128 | + result.country = component.short_name; |
| 129 | + } |
| 130 | + } |
| 131 | + result.addressLine1 = [result.streetNumber, result.streetName].join(' ').trim(); |
| 132 | + result.addressLine2 = ''; |
| 133 | + return result; |
89 | 134 | }
|
90 |
| - } |
| 135 | + }; |
91 | 136 |
|
92 | 137 | function isPluginApplied(domObj) {
|
93 | 138 | return getContextForElement(domObj) != undefined;
|
|
0 commit comments