Getting different latitude and longitude for same address line - google-maps-api-3

I am using Google API for getting latitude and longitude of address,
geocoder.geocode({ 'address': address
, bounds: map.getBounds() },
function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
Lat = results[0].geometry.location.lat();
Long = results[0].geometry.location.lng();
});
but for same address some times I get value : Latitude=33.189967 and longitude=-96.7333 which is more correct,
and other times I get array of Latitude and Longitude from which I pick up the first and the value I get is Latitude=41.920 and Longitude=83.41.
The address that I am currently using is '1550 South Custer Rd'.
Please help me some one.

I get 4 results for that string:
Found 4 results
[ 0 ]: 1550 South Custer Road, Monroe Charter Township, MI 48161, USA (41.9200564, -83.41902479999999)
[ 1 ]: 1550 South Custer Road, McKinney, TX 75070, USA (33.189967, -96.73350699999997)
[ 2 ]: 1550 South Custer Road, Spokane, WA 99223, USA (47.6389694, -117.34156009999998)
[ 3 ]: 1550 South Custer Road, Custer, MI 49405, USA (43.9296513, -86.21892639999999)
I don't know how you expect the Geocoder to know which of the answers is "more correct" as they all contain that exact string. Perhaps you need to include more information (like the town or the state), or process the results to determine the one that is in your area of interest.

Related

How can I get the key to increment when it is a string

I need to take someone’s age, and then outputs a key event from every year they have lived through.
dYearlyEvents = {
"1993": "Bill Clinton is inaugurated as the 42nd president.",
"1994": "The People's Republic of China gets its first connection to the Internet.",
"1995": "eBay is founded by Pierre Omidyar.",
"1996": "Murder of Tupac Shakur.",
"1997": "The first episode of Pokémon airs on TV Tokyo.",
"1998": "Death of Frank Sinatra.",
"1999": "The Columbine High School massacre in Colorado, United States, causes 15 deaths.",
"2000": "The Sony PlayStation 2 releases in Japan. ",
}
sBirthYear = (input("What year were you born in: \n"))
while True:
if sBirthYear in dYearlyEvents:
print(dYearlyEvents[sBirthYear])
sBirthYear += 1
This is what I tried but obviously as the input is a string it wont add a year every time it loops to print all events from 1993 to 2000 instead just prints 1993.

JOINing databases with SQLite

I have 4 databases relating to the America's Cup.
SELECT * FROM teams
>
Code | Country | TeamName
ITA |Italy | Luna Rossa Prada Pirelli Team
NZ |New Zealand | Emirates Team New Zealand
UK |United Kingdom | INEOS Team UK
USA |United States of America | NYYC American Magic
4 rows
SELECT * FROM races
>
Race Tournament Date Racedate
RR1R1 RR 15-Jan 18642
RR1R2 RR 15-Jan 18642
RR1R3 RR 16-Jan 18643
RR2R1 RR 16-Jan 18643
RR2R2 RR 17-Jan 18644
RR2R3 RR 17-Jan 18644
RR3R1 RR 23-Jan 18650
RR3R2 RR 23-Jan 18650
RR3R3 RR 23-Jan 18650
SFR1 SF 29-Jan 18656
1-10 of 31 rows
SELECT * FROM tournaments
>
Tournament Event TournamentName
RR Prada Cup Round Robin
SF Prada Cup Semi-Final
F Prada Cup Final
AC America's Cup Americas Cup
4 rows
SELECT *
FROM results
>
Race Code Result
FR1 ITA Win
FR1 UK Loss
FR2 UK Loss
FR2 ITA Win
FR3 UK Loss
FR3 ITA Win
FR4 ITA Win
FR4 UK Loss
FR5 ITA Win
FR5 UK Loss
1-10 of 62 rows
and I'm trying to write an SQL query that will output the number of races each team won by tournament, and show the output. The output table should include the full name of the Event, the Tournament and the full name of each team. My query at the moment looks like this:
SELECT TeamName, Result, Event, tournaments.Tournament
FROM teams LEFT JOIN results
ON teams.Code = results.Code
LEFT JOIN races
ON results.Race = races.Race
LEFT JOIN tournaments
ON races.Tournament = tournaments.Tournament
WHERE Result = 'Win'
ORDER BY tournaments.Tournament
which outputs:
TeamName Result Event Tournament
Emirates Team New Zealand Win America's Cup AC
Emirates Team New Zealand Win America's Cup AC
Luna Rossa Prada Pirelli Team Win America's Cup AC
Luna Rossa Prada Pirelli Team Win America's Cup AC
Emirates Team New Zealand Win America's Cup AC
Luna Rossa Prada Pirelli Team Win America's Cup AC
Emirates Team New Zealand Win America's Cup AC
Emirates Team New Zealand Win America's Cup AC
Emirates Team New Zealand Win America's Cup AC
Emirates Team New Zealand Win America's Cup AC
When I try to COUNT(Result) AS NumberOfWins, I get:
TeamName Result NumberOfWins Event Tournament
Luna Rossa Prada Pirelli Team Win 31 Prada Cup F
1 row
Why does adding the count count only Luna Rossa's wins? How can I change the query to fix it?
Why does adding the count count only Luna Rossa's wins?
Count() is an aggregate function and produces one result per GROUP.
As you have no GROUP BY clause the entire result set is a single group and hence the single result.
The reason why you got Tournament F is due to
If the SELECT statement is an aggregate query without a GROUP BY clause, then each aggregate expression in the result-set is evaluated once across the entire dataset. Each non-aggregate expression in the result-set is evaluated once for an arbitrarily selected row of the dataset. The same arbitrarily selected row is used for each non-aggregate expression. Or, if the dataset contains zero rows, then each non-aggregate expression is evaluated against a row consisting entirely of NULL values. As per SQLite SELECT -
How can I change the query to fix it?
So you need a GROUP BY clause. To create groups upon which the count() function will work on.
You probably want GROUP BY Tournament,TeamName
e.g.
SELECT TeamName, Result, Event, tournaments.Tournament, count(*)
FROM teams LEFT JOIN results
ON teams.Code = results.Code
LEFT JOIN races
ON results.Race = races.Race
LEFT JOIN tournaments
ON races.Tournament = tournaments.Tournament
WHERE Result = 'Win'
GROUP BY Tournament,Teamname
ORDER BY tournaments.Tournament

Selecting format for addresses returned from ggmap's revgeocode

When you grab the address for a geolocation in R it defaults to the first entry. How can I return one of the others instead?
revgeocode(c(-122.39150, 37.77374), output = "address")
Multiple addresses found, the first will be returned:
1145 4th St, San Francisco, CA 94158, USA
...
San Francisco County, CA, USA
San Francisco, CA, USA
California, USA
United States
You can use output="all" and then access the $results array to get the specific entry you want.
E.g.:
revgeocode(c(-122.39150, 37.77374), output = "all")$results[[6]]$formatted_address
This returns the 6th address, "San Francisco, CA 94158, USA".
Hope this helps!

Merge and update columns

I am trying to rebuild some MS Access update query logic with R's merge function, as the update query logic is missing a few arguments.
Table link Google drive
In my database "Invoice Account allocation", there are 2 tables:
Account_Mapping Table:
Origin Origin Postal Destination Destination Invoice
country code country postal code Account
FRA 01 GBR * ZR001
FRA 02 BEL * ZR003
BEL 50 ARG * ZR002
GER 01 ITA * ZR002
POL 02 ESP * ZR001
ESP 50 NED * ZR003
* 95 FRA 38 ZR001
BEL * * * ZR002
* * * * ZR003
FRA * FRA 25 ZR004
Load_ID
ID Origin Postal Destination Destination Default
country code postal code Invoice Account
2019SN0201948 FRA 98 FRA 38 XXAC001
2019SN0201958 POL 56 GBR 15 XXAC001
2019SN0201974 BEL 50 ARG 27 XXAC001
2019SN0201986 FRA 02 GER 01 XXAC001
The default invoice account in tables (Load_ID and Status_ID) is updated by the invoice account from the Account_Mapping table.
The tables Account_Mapping and Load_ID can be joined by:
Origin country & Origin country,
Origin Postal code & Postal code,
Destination country & Destination, and
Destination postal code & Destination postal code.
In the account_mapping table, there are several "*", it means the string value can take any value. I am not able build this logic with merge function. Please help me with a better logic.
New_Assigned_Account_Final <- merge(Load_ID, Account_Mapping, by.x =
c("Origin country","Postal code","Destination", "Destination postal code"),
by.y =
c("Origin country","Origin Postal code","Destination country", "Destination
postal code"))
Desired result:
Updated Load_ID table as below.
Load_ID:
ID Origin Postal Destination Destination Default
country code postal code Invoice Account
2019SN0201948 FRA 98 FRA 38 ZR003
2019SN0201958 POL 56 GBR 15 ZR003
2019SN0201974 BEL 50 ARG 27 ZR002
2019SN0201986 FRA 02 GER 01 ZR003
For the first ID, the default ID becomes "ZR003" because, "FRA" as Origin country doesn't have a Postal code - "98", so it falls under the all "*" bucket and is allocated to ZR003.
For the third ID, the default ID becomes "ZR002" because, "BEL" as Origin country has a Postal code - "50" associated with it, and the destination postal code of "ARG" can be anything because of the "*" in the Destination postal code column, therefore it is allocated to ZR002.
Thank you for your inputs.

geocode function removes special chracters

Hi I am using the geocode function to get lat and lng data for some cities, but for some special alphabet character cities such as: "Marcos Juárez Argentina" or "Perú Argentina" it creates mistakes in generating the inquiry:
https://maps.googleapis.com/maps/api/geocode/json?address=Per%FA%20Argentina&key=[**my api key**]
is there a way to fix that?
We can use the enc2utf8() function to read or set the declared encodings for a character vector:
> geocode(enc2utf8("Marcos Juárez Argentina"), output = 'more')
Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=Marcos%20Ju%C3%A1rez%20Argentina&sensor=false
lon lat type loctype address north south east west locality
1 -62.1058 -32.69786 locality approximate marcos juárez, cordoba, argentina -32.67304 -32.71417 -62.07497 -62.1302 Marcos Juárez
administrative_area_level_2 administrative_area_level_1 country
1 Marcos Juárez Department Cordoba Argentina
Or you can use a geocoding service that does not transliterate inputs: example
In Json:
https://geocode.xyz/Marcos%20Ju%C3%A1rez%20Argentina?json=1
{ "standard" : { "addresst" : {}, "city" : "Marcos Juárez", "prov" : "AR", "countryname" : "Argentina", "postal" : {}, "confidence" : "0.9" }, "longt" : "-62.10158", "alt" : {}, "elevation" : {}, "latt" : "-32.69679"}

Resources