On a certain website, I felt that the Google Maps flag of the facility was off, so Compare the latitude and longitude calculated from the address and facility name with the latitude and longitude specified on Google Maps.
If you search for Tokyo Tower on the Geocoding site, you can find the address and coordinates.
〒105-0011 4-2-8 Shibakoen, Minato-ku, Tokyo Tokyo Tower Coordinates: 35.658581, 139.745433
First, install geocoder.
pip install geocoder
Python code is very easy.
geocode.py
import geocoder
n = "Tokyo Tower"
a = "4-2-8 Shibakoen, Minato-ku, Tokyo"
p = [35.658581, 139.745433]
g = geocoder.google(a)
print(a, p,"<-->", g.latlng)
g = geocoder.google(n)
print(n, p,"<-->", g.latlng)
With this alone, I'm not sure how much it is off, so [Python code that calculates the distance from the latitude and longitude of two points] Borrow (http://blogs.yahoo.co.jp/qga03052/33991636.html) and calculate the distance.
geocode.py
import geocoder
import math
#Calculation of distance between two points(Python)
# http://blogs.yahoo.co.jp/qga03052/33991636.html
def deg2rad(deg):
return( deg * (2 * math.pi) / 360 )
def Hubeny(lat1, lon1, lat2, lon2) :
a =6378137.000
b =6356752.314140
e =math.sqrt( (a**2 - b**2) / a**2 )
e2 =e**2
mnum =a * (1 - e2)
my =deg2rad((lat1+lat2) /2.0)
dy =deg2rad( lat1-lat2)
dx =deg2rad( lon1-lon2)
sin =math.sin(my)
w =math.sqrt(1.0-e2 * sin *sin)
m =mnum /(w *w *w)
n =a/w
dym =dy*m
dxncos=dx*n*math.cos(my)
return( math.sqrt( dym**2 + dxncos**2) )
n = "Tokyo Tower"
a = "4-2-8 Shibakoen, Minato-ku, Tokyo"
p = [35.658581, 139.745433]
g = geocoder.google(a)
dist = Hubeny(p[0], p[1], g.latlng[0],g.latlng[1])
print(a, p,"<-->", g.latlng,dist)
g = geocoder.google(n)
dist = Hubeny(p[0], p[1], g.latlng[0],g.latlng[1])
print(n, p,"<-->", g.latlng,dist)
As a result, there was a deviation of several meters when I thought that they would match perfectly.
4-2-8 Shibakoen, Minato-ku, Tokyo[35.658581, 139.745433] <--> [35.6585817, 139.7454636] 2.771940296311124
Tokyo Tower[35.658581, 139.745433] <--> [35.6585696, 139.745484] 4.78817294783698
This degree of deviation is sufficient, but since there was a facility that was off by several hundred meters on Google Map, It is a good idea to web scrape the relevant part with BeautifulSoap etc. and verify it.
> var myLatLng = new google.maps.LatLng(37.695042, 140.127955);
Because it is often described in
r = re.compile(r'LatLng\((.*),(.*)\)')
m = re.search(r, str)
if m:
p = [float(m.group(1)),float(m.group(2))]```
It seems that you can find it with the regular expression.
Recommended Posts