Region/counties google place codes? - google-maps

Any one know in which ISO format google places returns the place object short_name for regions ?
I have this code:
var place = places.getPlace();
var type = place.address_components[0].types[0];
switch(type) {
case 'country': document.getElementById('country').value=place.address_components[0].short_name;
break;
case 'locality':
document.getElementById('town').value=place.address_components[0].long_name;
break;
default: //when is not a country or a city
document.getElementById('regioncode').value=place.address_components[0].short_name
;
In case is a region/county it gets the shor_name of it, but is some cases it returns a code like searching for "Balearic Islands, Spain" it return "PM" (which stands for ISO 3166-2:ES), but if I search "Kalmar län, Sweden" I get exactly the same for short_name as long_name which is "Kalmar County" instead of "H" (which stands for ISO 3166-2:SE)so my question is: Why Google sometimes return ISO 3166-2 values for regions/counties and sometimes the long_name value, is it any logic behind this? Can I force to ONLY return ISO values for short_names ??? thank you

According to Google Documentation:
short_name is an abbreviated textual name for the address component,
if available. For example, an address component for the state of
Alaska may have a long_name of "Alaska" and a short_name of "AK" using
the 2-letter postal abbreviation.
The Key word here is "if available". Kalmar County must not have a short name

Related

Filter function for phone number search in angular

Help with filter function!
I have a table with phone number and name as columns.
The JSON object would look something like this :
Details = [
{PN : '123-456-7890',
NAME : 'PERSON A',
},{
PN: '192-453-7655',
NAME: 'PERSON B',
}
]
I need to search on keyup and filter the data. The user can search in any of these patterns:
xxxxxxxxxx,
xxx-xxx-xxxx,
xxx-xxxxxxx,
xxxxxx-xxxx.
and still needs to get the data having xxx-xxx-xxxx as phone number in the table. Search should start as soon as the keyup triggers.
I tried using match and test methods, but couldn't make connection between search input, regex and the elements from table.
Can anyone suggest how I can tackle this situation?
Please use this regex -
/^\d{3}-\d{3}-\d{4}$|^\d{3}-\d{7}$|^\d{6}-\d{4}|^\d{10}$/
Angular Code -
matchNumber(){
var str = "12311111455";
var res = str.match(/^\d{3}-\d{3}-\d{4}$|^\d{3}-\d{7}$|^\d{6}-\d{4}|^\d{10}$/);
if(res.length > 0){
console.log('Matched);
}}
Valid Numbers
1234567890
123-456-7890
123-4567890
123456-7890
Invalid Numbers
123453647564756876
111223-234234
Check DEMO -
Check Valid Numbers

How to parse and map multiple fields from 1 excel cell

I've got a CSV parser and the file has multiple strings which I need to map to different fields within one excel cell.
So the example image above I have the postcode, state, and suburb which are all in the same cell - but I need to map these to their respective tables in the database.
How would I do this? The team is saying likely regex, if so what would be the regex I use?
Cheers guys!
I expect each type of data to be split into the relevant data table
Regex they say? Then you will have two problems.
Tackle this with extracting the postcode, then a string split. Here in psuedo code:
For i = 1 to lines.Length
string s = lines[i];
string postCode = s[s.Length -4]; // Get postcode
s = s[0, s.Length -4].TrimEnd(); //Remove postcode and trim last space
arr[] = s.Split(" "); // Split words into array
string state= arr[arr.Length - 1]; //The last word is the state
string suburb;
For j = 0 to arr.Length - 1
suburb += arr[j];
Next j
Next i
Not sure what language/framework you're using, but I'm just posting this in vanilla javascript.
The regex I'd use for each cell is:
/([\w\s]+)\s([A-Z]{2,3})\s(\d{4})/
Which breaks down into:
([\w\s]+) capture multiple words or spaces
\s followed by a space
([A-Z]{2,3}) capture a group of two or three capital letters
\s followed by a space
(\d{4}) capture four digits
I always find https://www.regexpal.com really useful to write and test my regexes.
Using that in javascript:
const addresses = [
'Elizabeth Bay NSW 2011',
'Sydney NSW 2000',
'St Kilda VIC 3182',
'Sausage 1234567890',
'Middle Park QLD 4047',
'The Big Pineapple QLD 4559',
'Uluru NT 0872'
]
const reg = /([\w\s]+)\s([A-Z]{2,3})\s(\d{4})/
const matches = addresses.map(address => {
const match = address.match(reg)
return match && match.slice(1)
})
console.log(matches)
Will give you:
// Matching string, Suburb, State, Postcode
["Elizabeth Bay NSW 2011", "Elizabeth Bay", "NSW", "2011"]
["Sydney NSW 2000", "Sydney", "NSW", "2000"]
["St Kilda VIC 3182", "St Kilda", "VIC", "3182"]
null // The non-matching entry
["Middle Park QLD 4047", "Middle Park", "QLD", "4047"]
["The Big Pineapple QLD 4559", "The Big Pineapple", "QLD", "4559"]
["Uluru NT 0872", "Uluru", "NT", "0872"]

Geocoder.geocode({'placeId': placeId}) doesn't return administrative_area_level_2/1

I have problem with result of Geocoder.geocode({'placeId': placeId}) on specific location
(i.e. Main Street 34, Paris) then I will get address_components: street,sublocality,locality,country,postal_code.
function geocodePlaceId(geocoder, placeId, callback) {
geocoder.geocode({'placeId': placeId}, function(results, status) {
if (status === google.maps.GeocoderStatus.OK) {
if (results[0]) {
console.log(results[0]);
callback(results[0].address_components);
}
});
}
code above for the precise location (which contains street nmbr. street and city) returns address_components that are not important for me.
However I want administrative_area_level_2 and administrative_area_level_1 types. Unfortunately I googled a lot and nothing. I thought that this definition for my request can be helpfull
https://developers.google.com/maps/documentation/javascript/3.exp/reference#GeocoderComponentRestrictions but not.
Example: https://maps.googleapis.com/maps/api/geocode/json?&address=luka%20666%20brusno
I created request with exact address with street, number, city and returned address_components which contains only these keys: route, locality, country and postal_code,
but if i change a request to .. address=brusno result contains administrative_area_level_2 and administrative_area_level_1. How can i got administrative_area_level_1 and administrative_area_level_2 for first option?
Do you have some idea how can I resolve this issue or can I influence returned types of address_components?
Based on the Google Maps Geocoding documentation, administrative_area_level_# indicates a civil entity below the country level. And not all nations exhibit these administrative levels. In most cases, administrative_area_level_# short names will closely match ISO 3166-2 subdivisions and other widely circulated lists; however this is not guaranteed as our geocoding results are based on a variety of signals and location data. So maybe that is the issue.
Also, regarding about the request using only the address=brusno, you will notice here that the administrative_area_level_# here is in the Banská Bystrica District not in the place that you use like Luka, Brusno.
If you query that address you will notice that it is the same result.
using address=Banská Bystrica District
https://maps.googleapis.com/maps/api/geocode/json?&address=Bansk%C3%A1%20Bystrica%20District
So maybe like the documentation state that not all place(Luka, Brusno)exhibit these administrative levels.

Converting non-JSON text string into JSON object

I have this simple string repeated 1000's of times for worldwide weather widget I'm using in a large text file:
City Name = "Albuquerque, NM, US" Location = "NAM|US|NM|ALBUQUERQUE" Country = "United States"
Notice how it's formatted.
CITY NAME
LOCATION
COUNTRY
The string I'm actually passing into the Widget is the LOCATION string: "NAM|US|NM|ALBUQUERQUE"
So what I'm trying to do is convert the first example of the CITY NAME, LOCATION and COUNTRY into a JSON OBJECT.
Then, once I have that, I wish to allow the user to INPUT their current location or any location for that matter thereby passing the user input into this:
$('#digiclock').jdigiclock({
// Configuration goes here
clockImagesPath: "images/clock/",
weatherImagesPath: "images/weather/",
am_pm: false,
weatherLocationCode: "NAM|US|TN|CHATTANOOGA",
weatherMetric: "F",
weatherUpdate: "5",
proxyType: "php"
});
The weatherLocationCode is actually the LOCATION in the string above. So when the user inputs their CITY/STATE or just CITY, I want to parse the newly formed JSON object from the above text, capture the location, and stick-it up in the function.
This is what the end result should be:
// JSON OBJECT
{data : [
{
"City Name" : "Aachen, DE",
"Location" : "EUR|DE|GM011|AACHEN",
"Country" : "Germany"
}
]
}
Simple? Not so much.

google.maps.Geocoder.geocode not always returns Australian postcode

I'm using the google.maps.Geocoder class to resolve Australian addresses entered into a free form input field:
pass the entered address (such as "Parramatta") in the google.maps.GeocoderRequest.address field,
call google.maps.Geocoder.geocode
and then show all returned google.maps.GeocoderResult.formatted_address fields to the user so they can select one.
Problem is that the returned formatted_address fields not always contains the postcode.
Pass "Parramatta" into google.maps.GeocoderRequest.address ->
receive formatted_address "Parramatta NSW, Australia"
Pass "Strathfield" into google.maps.GeocoderRequest.address ->
receive formatted_address "Strathfield NSW 2135, Australia"
Looks to me like this is a fault in Google's database, but I'm not sure.
Is there a way to resolve addresses that always gives you the postcode?
If you reverse geocode the location returned for Parramatta, it does contain a post code:
{
"long_name": "2150",
"short_name": "2150",
"types": [
"postal_code"
]
}
That is correct according to Wikipedia