kylex
kylex

Reputation: 14406

Google maps Polygon question

The following is an example of how to greate a polygon in the google maps API.
What is the purpose of latOffset and lonOffset?
We're creating an array of points to make a polygon, but what exactly is the offset doing?

var map = new GMap2(document.getElementById("map_canvas"));
map.setCenter(new GLatLng(37.4419, -122.1419), 13);
map.addControl(new GSmallMapControl());
GEvent.addListener(map, 'click', function(overlay, latlng) {
  var lat = latlng.lat();
  var lon = latlng.lng();
  var latOffset = 0.01;
  var lonOffset = 0.01;
  var polygon = new GPolygon([
    new GLatLng(lat, lon - lonOffset),
    new GLatLng(lat + latOffset, lon),
    new GLatLng(lat, lon + lonOffset),
    new GLatLng(lat - latOffset, lon),
    new GLatLng(lat, lon - lonOffset)
  ], "#f33f00", 5, 1, "#ff0000", 0.2);
  map.addOverlay(polygon);
});

Upvotes: 1

Views: 1604

Answers (2)

Fawad Ghafoor
Fawad Ghafoor

Reputation: 6207

change both to o.02 u ll feel the difference. the polygone ll be bigger in size

Upvotes: 0

Nosredna
Nosredna

Reputation: 86206

It's just building a diamond around the point (lat,lon).

     *

  *  O  *

     *

Lat is latitude and lon is longitude. The offsets are how far away from the center point the corners of the diamond are.

I wonder how well it works at the north pole.

Upvotes: 5

Related Questions