library(ggmap) library(rgdal) cities<-c("city A","city B") country<-readOGR(dsn=".",layer="country") gc<-geocode(cities,source="google") gc$names<-c("city A","city B") coordinates(gc)<-~lon+lat proj4string(gc)<-proj4string(country) #because the "gc" doesnt have a crs at the moment gc<-spTransform(gc,CRS(proj4string(country))) plot(country) plot(gc,add=T)
Result is that the points are not in the map at all. What is wrong? CRS, projection is the same, so it should have been working.
The point of this endeavor is to make the "cities" to appear in the shapefile of the country. Something in the projection has to be wrong although they appear to be the same.
The reason i put
proj4string(gc)<-proj4string(country) before the
spTransform line is because you can't use the
spTransform function on something that has NA values for projection.
summary()) and see what you get - perhaps edit and paste the results of
summary()in the question here?