add type field (still needs a better Ox.Select)
This commit is contained in:
parent
b299674717
commit
60662a437a
4 changed files with 130 additions and 26 deletions
|
|
@ -858,9 +858,7 @@ Ox.Map = function(options, self) {
|
|||
name: data.formatted_address.split(', ')[0],
|
||||
north: bounds.getNorthEast().lat(),
|
||||
south: bounds.getSouthWest().lat(),
|
||||
types: data.types.map(function(type) {
|
||||
return Ox.toTitleCase(type.replace(/_/g, ' '));
|
||||
}),
|
||||
type: getType(data.address_components[0].types),
|
||||
west: bounds.getSouthWest().lng()
|
||||
};
|
||||
function getCountryCode(components) {
|
||||
|
|
@ -883,7 +881,45 @@ Ox.Map = function(options, self) {
|
|||
return !country && (
|
||||
i == 0 || name != components[i - 1].long_name
|
||||
) ? name : null;
|
||||
}).join(', ')
|
||||
}).join(', ');
|
||||
}
|
||||
function getType(types) {
|
||||
Ox.print('getType', types)
|
||||
// see http://code.google.com/apis/maps/documentation/javascript/services.html#GeocodingAddressTypes
|
||||
var strings = {
|
||||
'country': ['country'],
|
||||
'region': ['administrative_area'],
|
||||
'city': ['locality'],
|
||||
'borough': ['neighborhood', 'sublocality'],
|
||||
'street': [
|
||||
'intersection', 'route',
|
||||
'street_address', 'street_number'
|
||||
],
|
||||
'premise': [
|
||||
'airport', 'establishment', 'park',
|
||||
'premise', 'subpremise'
|
||||
],
|
||||
'feature': ['natural_feature']
|
||||
},
|
||||
type = 'other';
|
||||
Ox.forEach(strings, function(values, key) {
|
||||
Ox.forEach(values, function(value) {
|
||||
if (find(value)) {
|
||||
type = key;
|
||||
return false;
|
||||
}
|
||||
});
|
||||
return type == 'other';
|
||||
});
|
||||
return type;
|
||||
function find(type) {
|
||||
var ret;
|
||||
Ox.forEach(types, function(v) {
|
||||
ret = Ox.startsWith(v, type);
|
||||
return !ret;
|
||||
});
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
return place;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue