No commit activity in last 3 years
No release in over 3 years
Converts WSG84 Coordinates via Mercator-projection to meters and tiles
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 2.5
 Project Readme

Simple Mercator Location

Build Status Coverage Status Code Climate Dependency Status Gem Version

A Ruby lib that uses the Mercator Projection to convert WSG84 coordinates (latitude, longitude) to meters, pixels and tiles.

Usage

Just add it to your Gemfile:

gem "simple_mercator_location"

Calculating the googe maps tile numbers for a given lat/lon at a specified zoom level

place = {lat: 40.689359, lon: -74.045197}
SimpleMercatorLocation.new(place).zoom_at(11).to_tile # <= [602,770]

You can use these data to get a tile for a given location via google map url:

https://khms0.google.com/kh/v=131&src=app&x=602&y=770&z=11&s=Gal

Convert lat/lon to pixels at a given zoom level for google maps

At its first zoom level (0), google assumes the world tile to display the whole world. At a higher zoom level n (>2), google uses 2^n tiles to display the whole world. Every tile has 256x256 pixels. #to_px retuns the pixels on the whole map for a given zoom level.

place = {lat: 49.38237278700955, lon: 8.61328125}
SimpleMercatorLocation.new(place).zoom_at(11).to_px  # <= [274688, 179200]

Convert lat/lon to Google World coordinates

Google assumes his "world tile" to show the whole wold in one tile with the size of 256x256px. So the world coordinates are the latitude and longitude coordinates mapped to this world tile. Whereby the origin of googles world coordinate system resides in the center.

place = {lon: -87.65005229999997, lat: 41.850033}
SimpleMercatorLocation.new(place).to_w  # <= [65.67107392000001, 95.1748950436046]

Convert lat/lon to meters

place = {lon: 12.12890625, lat: 48.22467264956519}
SimpleMercatorLocation.new(place).to_m  # <= [1350183.66762935, 6144314.08167561]

Bitdeli Badge