Sait
Sait

Reputation: 19815

Google maps show coordinates on map

I have 100 coordinates (latitude, longitude). I want to produce a static image (png, pdf) or if possible, interactive interface (in a browser) to show these points on the world map.

I am thinking Google Map's might have an API for this, however I haven't used anything like that before. So, not sure where/what to look for. Can you give me some keywords/links/code samples?

Upvotes: 0

Views: 5265

Answers (2)

kylieCatt
kylieCatt

Reputation: 11039

You can do something similar to this using Google Maps:

var map
function initialize() {
  var mapOptions = {
    // map options
  };
  map = new google.maps.Map(document.getElementById("map-canvas"), mapOptions);
}
google.maps.event.addDomListener(window, 'load', initialize);

var coordinates = [{latitude: 42, longitude: 42, title: "A Title"},...]

for(var i = 0; i < coordinates.length; i++){
  var loc = new google.maps.LatLng(coordinates[i].latitude, coordinates[i].longitude);
  var marker = new google.maps.Marker({
     position: loc,
     map: map,
     title: coordinates[i].title
  });
}

How exactly you get the coordinate data to your template is another issue but it can be done pretty easily with AJAX using Flask or Django (or any other web framework but I am most familiar with those 2).

And for your template:

<head>
  <script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=YOUR-KEY"></script>
</head>
<div id="map-canvas"></div>

Upvotes: 2

Stiffo
Stiffo

Reputation: 818

  1. You could create KML files and open them in Google Earth or Google Maps.
  2. Or you could use this library: pygmaps
  3. Here is a talk on using Python to create maps

Upvotes: 1

Related Questions