简体   繁体   中英

Change in Google Maps API v3 on Feb 10, 2015 breaks existing maps created using plotGoogleMaps in R?

Update: Apr 15, 2015: Google looked into making latest Maps API backwards compatible to fix this problem but issued a "won't fix" decision.

Update: Feb 11, 2015: Believe this to be a problem that is caused by an update to the experimental version of Google Maps API 3.19 on Feb 10, 2015: https://developers.google.com/maps/documentation/javascript/3.exp/reference

Have been in touch with the owner of the plotGoogleMaps package - can confirm that specifying v3.18 does generate maps that work correctly.

Unless the issue in v3.19 is fixed before becoming the "release" version, all prior maps created by plotGoogleMaps will no longer function correctly.

Original Post: This question is for users of the plotGoogleMaps package in R and for the Google Maps API support team.

Maps created prior to February 10, 2015 using the aforementioned R package are behaving differently starting this evening (Eastern Time). Specifically, the "info box" that appears when you click on the first map pin is then used when you click on any other pin on the map.

A reproducible R code example taken from Milan Kilibarda's tutorial (here: http://cran.r-project.org/web/packages/plotGoogleMaps/vignettes/plotGoogleMaps-tutorial.pdf ).

data(meuse)
coordinates(meuse)<-~x+y 
# convert to SPDF 
proj4string(meuse) <- CRS('+init=epsg:28992') 
# adding Coordinate Referent Sys.
# Create web map of Point data 
m<-plotGoogleMaps(meuse,filename='myMap1.htm')

When you click on a map pin, the info box that opens becomes the same info box opened for every other map pin. Htm map files created by plotGoogleMaps from several months ago now exhibit this same behavior so I am thinking this is a result of a change to the Google Maps API service.

Another example in the tutorial that used to work is plotting a SpatialPolygonsDataFrame using the following R code:

require(plotGoogleMaps)
require(maptools)
require(RColorBrewer)
nc <- readShapeSpatial(system.file("shapes/sids.shp",package="maptools")[1],
                       proj4string=CRS("+proj=longlat +datum=NAD27"))
m<-plotGoogleMaps(nc,zcol="NWBIR74",filename='MyMap6.htm',
                  mapTypeId='TERRAIN',
                  colPalette= brewer.pal(7,"Reds"), strokeColor="white")

When you click on a polygon, the info box opens in the top left corner (it should open where the click is registered) and it does not change when you click a different polygon. As an aside, in the past, although the info box would open in the top left corner, it would eventually move to the click point after 3 clicks. As of today, the contents of the info box does not change.

This behavior can be observed by loading a previously created Google map using plotGoogleMaps, not just maps created as of today.

I am thinking that the above problems are caused by a change on Google's end (since previously created maps now exhibit the same behavior). I have tested this on both a Mac with different browsers (Safari 7.1.3, Firefox 34.0.5, Chrome 40.0.2214.111) and on a PC using IE 10.0.9200.17183 and the same results occur.

I am using R 3.1.2 and the latest version of plotGoogleMaps.

If anyone from the Google Maps team reads this, can you please verify whether an update on your end is causing this and if so, when can we expect a fix?

Thanks in advance.

Google developers changed something with the API, InfoWindows do not work properly now with plotGooogleMaps code. This problem can be overcome in two ways:

1) Install new version (2.2) of the package from R-forge (RECOMENDED, I hope it will soon on the CRAN)

install.packages("plotGoogleMaps",repos="http://r-forge.r-project.org")

2) If plotGoogleMaps 2.1 is used. Change the api link in the functions eg if you use CRAN version set the api argument to version 3.18.

# Data preparation
# Point data
data(meuse)
coordinates(meuse)<-~x+y 
# convert to SPDF 
proj4string(meuse) <- CRS('+init=epsg:28992') 
# adding Coordinate Referent Sys.
# Create web map of Point data 
m<-plotGoogleMaps(meuse , api="https://maps.google.com/maps/api/js?sensor=false&v=3.18")

The problem with existing maps made before 2014/02/10 can be solve only if you replace api in your .html (.htm) files. You should replace the line

<script type="text/javascript" src="https://maps.google.com/maps/api/js?sensor=false"> </script>

with

<script type="text/javascript" src="https://maps.google.com/maps/api/js?sensor=false&v=3.18"</script>

I hope this helps.

New issue May 2015. This old api doesn't work anymore. So, if you reproduce maps with new version you will not have a problem, but if you need to use old maps you should then replace these lines:

replace - infowindow.content= WITH infowindow.setContent(

replace - infowindow.position =event.latLng; WITH - ); infowindow.setPosition(event.latLng);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM