Skip to content Skip to sidebar Skip to footer

Easiest Way In R Or Python To Add Image/video In Map Plot Marker Click Popup/infowindow

I have many different (lat,long data) points of world associated with unique place names and corresponding each point specific image or video data. Now I want to create an html fil

Solution 1:

Assuming you already have a list of URLs for images and/or videos, it would literally be as simple as iterating through them in JavaScript, and assembling the HTML in JavaScript. It would be unnecessarily complicated to make a ton of HTML pages, and have to call them.

var images = [{url:"http://images.com/rome.png", position:new google.maps.LatLng()}, ....];
var videos = [{url:"http://videos.com/borneo.wav", position:new google.maps.LatLng()}, ....];
for(var i=0l i<images.length; i++){
  var m = new google.maps.Marker({position:images[i].position});
  m.infow = new google.maps.InfoWindow("HTML using image template, splicing in the URL using '+''s");
  google.maps.event.addListener(m, 'click', function(){
    this.infow.setPosition(this.getPosition());
    this.infow.open(map);
  });
}
//same for videos

Instead of copy and paste, this will be efficient, readable, and scalable.

Therefore, as far as I understand your problem, you do not need Python or R to solve it.


Solution 2:

In R you can do this using my package googleway which has a Google Maps widget. You can customise marker info windows with normal html.

To use Google Maps you'll also need a valid Google Maps API key

library(googleway)

#key <- "your_api_key_here"

df <- data.frame(lat = -37.817714,
                 lon = 144.967260,
                 info = '<div id="bodyContent"><iframe width="640" height="390" src="//www.youtube.com/embed/a8UOzBUZxCw" frameborder="0" allowfullscreen></iframe></div>')

google_map(key = key, height = 600, search_box = T) %>%
    add_markers(data = df, info_window = "info")

enter image description here


Post a Comment for "Easiest Way In R Or Python To Add Image/video In Map Plot Marker Click Popup/infowindow"