Search code examples
rgoogle-earthggmapgeopoints

ggmap and Google Earth not giving same position (R)


I'm currently trying to plot the position of some weather stations in Switzerland. Using pretty standard code with ggmap and geom_point.

register_google(key = "YOUR KEY") 
map <- get_map(location='Bern', zoom=12, maptype = "terrain", color = "color")
ggmap(map) + geom_point( aes(x=stations_coord$long, y=stations_coord$lat)
                         , data = stations_coord, colour = "red", size = 3 )

Problem: All values are misplaced in the plot when comparing to Google Earth

Here is an example for the Bern station. enter image description here

I really don't understand how this is possible. Also there are no threads on this issue anywhere.

enter image description here

Could anyone help me?


Solution

  • The satellite map and terrain maps use different datums. You are comparing a satellite image with a terrain map - those are different maps and are likely to use different datums. The default datum for google earth (the screencap of your web browser) is WGS84. I don't know what the default datum for the terrain map is but it appears to be different.

    Try changing 'maptype = "satellite"' and you will get the same lat/long:

    map <- get_map(location='Bern', zoom=12, maptype = "satellite", color = "color")
    ggmap(map) + geom_point( aes(x=stations_coord$long, y=stations_coord$lat)
                            , data = stations_coord, colour = "red", size = 3 )
    

    Futher reading on datums: https://en.wikipedia.org/wiki/Geodetic_datum

    A side note: accidents happen all the time because of this. Ships reading GPS are using one datum and their charts (maps) are in another datum, so they aren't where they think they are and can crash into stuff. This can also happen with aircraft and in land navigation.

    Bottom line: ggmap uses the datums associated with the map that you tell it to look at. You are telling ggmap to look at one type of map (terrain) and comparing it with another type of map (satellite) - probably different datums.