1

Do you have any experience with adding custom polygons in to the google maps?

I have made polygons from raster layer and my goal is to show this layer in google maps.

For now i have experience with showing points from mysql in google maps.


I have used raster to vector so they are in shapefile.

1

The Google Maps API has a method that allows you to construct polygons from coordinates and add them to your map.

Here is a simple example from the Google Maps API documentation.

Code:

// This example creates a simple polygon representing the Bermuda Triangle.

function initMap() {
  var map = new google.maps.Map(document.getElementById('map'), {
    zoom: 5,
    center: {lat: 24.886, lng: -70.268},
    mapTypeId: google.maps.MapTypeId.TERRAIN
  });

  // Define the LatLng coordinates for the polygon's path.
  var triangleCoords = [
    {lat: 25.774, lng: -80.190},
    {lat: 18.466, lng: -66.118},
    {lat: 32.321, lng: -64.757},
    {lat: 25.774, lng: -80.190}
  ];

  // Construct the polygon.
  var bermudaTriangle = new google.maps.Polygon({
    paths: triangleCoords,
    strokeColor: '#FF0000',
    strokeOpacity: 0.8,
    strokeWeight: 2,
    fillColor: '#FF0000',
    fillOpacity: 0.35
  });
  bermudaTriangle.setMap(map);
}
  • Yes , thanks but if I try to add geometry to polygons I only add area and perimeter – ABCD Oct 2 '15 at 18:23
  • I don't understand the issue you are having. If you have polygons in an existing database you will need to take the coordinates that make up each polygon vertex and build your coordinate list as in the above code. Do you know how to parse out the vertex coordinate pairs? – Radar Oct 2 '15 at 18:26
  • They are not in database. For now I have only polygons from raster. And if I try to add coordinates to them I can only add area and perimeter. – ABCD Oct 2 '15 at 18:29
  • What format are the polygons in? Shapefile? File Geodatabase? – Radar Oct 2 '15 at 18:32
  • I have used raster to vector so they are stored as shapefile. – ABCD Oct 2 '15 at 21:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.