Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to locate a latitude and longitude with jVector Map Plugin

I know that google maps has markers to highlight certain points in the map. I am for some reason not comfortable putting this type of map on my site and love the jvector map effects. But I am not able to figure out how to define markers in the jVectorMap, does anybody have a clue as to how to define the markers in jVectorMap and highlight those points. I would also love to know how would you get to the certain point in jVector Map using latitude and longitude.

Thanks.

like image 266
defau1t Avatar asked Oct 30 '11 07:10

defau1t


2 Answers

Now you can do that, new version of jVectorMap (0.2) introduces such feature with markers parameter. Check out demo here http://jvectormap.com/examples/markers-world/.

like image 125
bjornd Avatar answered Nov 14 '22 23:11

bjornd


The jVectorMap world map uses the van der Grinten projection. The formula to convert from/to the map can be found this Wikipedia and Wolfram article.

You'll need to scale it to your map's size & offset, given the above formula projects the long/lat (-180 to 180 deg) to a (-1 to +1) cartesian grid.

Also, the angles in the formula should be in radians, not in degrees.

function vanDerGrinten(lat, lng) {
    lat = lat * Math.PI / 180;
    lng = lng * Math.PI / 180;
    var lng0 = 0;
    var A1 = 0.5 * Math.abs((Math.PI / (lng - lng0) - (lng - lng0) / Math.PI));
    var phi = Math.asin(Math.abs(2 * lat / Math.PI));
    var G = Math.cos(phi) / (Math.sin(phi) + Math.cos(phi) - 1);
    P = G * (2 / Math.sin(phi) - 1);
    Q = A1 * A1 + G;
    x0 = A1 * A1 * (G - P * P) * (G - P * P) - (P * P + A1 * A1) * (G * G - P * P);
    x1 = (A1 * (G - P * P) + Math.sqrt(x0));
    x2 = (P * P + A1 * A1);
    x = sgn(lng - lng0) * Math.PI * x1 / x2;
    y = sgn(lat) * Math.PI * Math.abs(P * Q - A1 * Math.sqrt((A1 * A1 + 1) * (P * P + A1 * A1) - Q * Q)) / (P * P + A1 * A1);
    return { _x: x, _y: y };
}
like image 36
Tanios Kahi Avatar answered Nov 14 '22 23:11

Tanios Kahi