R trying to find latitude/longitude data for cities in europe and getting geocode error messege

后端 未结 4 593
情书的邮戳
情书的邮戳 2021-02-04 09:46

I recently posted a question regarding plotting postions on cities in europe as points on a map. See R, get longitude/latitude data for cities and add it to my dataframe

4条回答
  •  余生分开走
    2021-02-04 10:12

    You can use below code to extract information from Bing Map API

    for(i in 1:length(PinCode)){
    var = PinCode[i]
    link=paste("http://dev.virtualearth.net/REST/v1/Locations?postalCode=", var, "&o=xml&maxResults=1&key=[YOurKey]",sep = "")
    data<- xmlParse(link)
    xml_data <- xmlToList(data)
    PinCodeLatLongtemp <- data.frame(PinCode = "Temp", Lat = "Lat", Long = "Long")
    PinCodeLatLongtemp$PinCode <- var
    PinCodeLatLongtemp$Lat <- 
    xml_data$ResourceSets$ResourceSet$Resources$Location$Point$Latitude
    PinCodeLatLongtemp$Long <- 
    xml_data$ResourceSets$ResourceSet$Resources$Location$Point$Longitude
    
    PinCodeLatLong <- rbindlist(list(PinCodeLatLongtemp,PinCodeLatLong), fill = T)
    }
    

    It will create a new dataframe with you input 'Pincode' and Two new columns with Lat and Long. YOu can get your key from [here] (https://www.bingmapsportal.com)

提交回复
热议问题