More

How to point out a city from a map image of world with longitude and latitude?

How to point out a city from a map image of world with longitude and latitude?


have a map image 800px wide. How can I figure out a city.

like New York has 40.75 latitude and -73.98 longitude. I have to pin a mark over this point.

Before I have done with x_axis and y_axis which gives problem on more cities figure because i manually had to input values. now i have database with all cities with latitude and longitude. or is there any way that i can convert latitude and longitude to x and y axis.

Thank you

EDIT

x = image.width * (longitude + 180) / (2 * 180) y = image.height * (latitude + 180) / (2 * 180)

The maths is pretty easy if you want to do it by hand(or in the database) but you will probably be best served by setting up a desktop GIS to draw the output image once or if you need interactivity then a web map server will be a better way to go.


  1. On your computer, open Google Maps.
  2. In the search box at the top, type your coordinates. Here are examples of formats that work:
    • Degrees, minutes, and seconds (DMS): 41°24'12.2"N 2°10'26.5"E
    • Degrees and decimal minutes (DMM): 41 24.2028, 2 10.4418
    • Decimal degrees (DD): 41.40338, 2.17403
  3. You'll see a pin show up at your coordinates.
  1. On your computer, open Google Maps.
  2. Right-click the place or area on the map.
  3. Select the latitude and longitude, this will automatically copy the coordinates.

This is called Reverse Geocoding

Documentation from Google:

Sample Call to Google's geocode Web Service:

Here is a complete sample:

In node.js we can use node-geocoder npm module to get address from lat, lng.,

Here is the latest sample of Google's geocode Web Service

Simply change the YOUR_API_KEY to the API key you get from Google Geocoding API

P/S: Geocoding API is under Places NOT Maps )

Here's a modern solution using a promise:

The promise returns the address object in 'then' or the error status code in 'catch'

Following Code Works Fine to Get City Name (Using Google Map Geo API) :

In case if you don't want to use google geocoding API than you can refer to few other Free APIs for the development purpose. for example i used [mapquest] API in order to get the location name.

you can fetch location name easily by implementing this following function


Pixel coordinates

Pixel coordinates reference a specific pixel on the map at a specific zoom level, whereas world coordinates reflect absolute locations on a given projection. Pixel coordinates are calculated using the following formula:

From the above equation, note that each increasing zoom level is twice as large in both the x and y directions. Therefore, each higher zoom level results in a resolution four times higher than the preceding level. For example, at zoom level 1, the map consists of 4 256x256 pixels tiles, resulting in a pixel space from 512x512. At zoom level 19, each x and y pixel on the map can be referenced using a value between 0 and 256 * 2 19 .

Because we based world coordinates on the map's tile size, a pixel coordinate's integer part has the effect of identifying the exact pixel at that location in the current zoom level. Note that for zoom level 0, the pixel coordinates are equal to the world coordinates.

We now have a way to accurately denote each location on the map, at each zoom level. The Maps JavaScript API constructs a viewport given the zoom level center of the map (as a LatLng ) and the size of the containing DOM element, and translates this bounding box into pixel coordinates. The API then determines logically all map tiles which lie within the given pixel bounds. Each of these map tiles are referenced using tile coordinates which greatly simplify the displaying of map imagery.


Frequently Asked Questions

What counts as a city/town?

Any populated place in the world as determined by U.S. government agencies. Neighborhoods within listed cities are not included.

Were does your data come from?

Cities for all non-U.S. countries comes from the National Geospatial-Intelligence Agency. US cities data comes from the U.S. Census Bureau and the U.S. Geological Survey. The basic database and population data comes from Natural Earth Data. Population density data comes from the Center for International Earth Science Information Network at Columbia University in partnership with NASA's Socioeconomic Data and Applications Center. We've made a concerted effort to source our data from public domain and permissively-licensed sources that will not restrict the rights of our customers.

How do you address border conflicts and territorial disputes?

We simply use the determination of our sources: U.S. government agencies.

Since most of this data is in the public-domain, what value are you adding?

We've spent countless hours: downloading, merging, cleaning, formatting, and aggregating this data into an accurate and concise product.

What am I allowed to do if I purchase the Comprehensive Database license?

A license allows you to use the database internally or to query the database for public-facing applications that you or your organization owns or develops. Attribution is not required. You are not allowed to publicly redistribute the database without prior permission. You can make copies of the database for internal and backup purposes. To learn more, read the full license terms.

Why should I trust this data?

This database was aggregated from authoritative sources and carefully processed by SimpleMaps. We've been developing and selling interactive maps to Fortune 500 companies and prominent international organizations for over 10 years. Over this time, we've learned a lot about geographic data. Our data products have been used in production by well-regarded organizations such as The Guardian. To get a sense of the expertise, check out some of the testimonials from our happy customers.

How do I calculate the distance between two cities?

Can I get the Pro or Comprehensive Database in Excel or SQL server?

The Comprehensive Database can be downloaded in CSV or SQL (MySQL) format upon purchase. The database has too many rows to fit in a single Excel worksheet, but we can provide the data in Excel format, broken out by country, upon request. We can also provide the data as a .bak file for SQL server. Please contact us to receive the data in one of these formats.

What's the fastest way to import the comprehensive database into MySQL?

We recommend using the CSV file and following our tutorial on importing a CSV into MySQL.

Can I purchase additional updates?

Yes. After updates expire, you can purchase 12 more months of updates for $99 (Pro) or $199 (Comprehensive).

What is the difference between the Pro and Comprehensive databases?

The main difference between the two is that the Pro database generally only includes cities and towns that either have a ranking of 1, 2, or 3 while the Comprehensive database includes all cities and towns for which we have data. For most users, the Pro database is sufficient and will be faster to query.


Frequently Asked Questions

What counts as a city/town?

Any populated place in the world as determined by U.S. government agencies. Neighborhoods within listed cities are not included.

Were does your data come from?

Cities for all non-U.S. countries comes from the National Geospatial-Intelligence Agency. US cities data comes from the U.S. Census Bureau and the U.S. Geological Survey. The basic database and population data comes from Natural Earth Data. Population density data comes from the Center for International Earth Science Information Network at Columbia University in partnership with NASA's Socioeconomic Data and Applications Center. We've made a concerted effort to source our data from public domain and permissively-licensed sources that will not restrict the rights of our customers.

How do you address border conflicts and territorial disputes?

We simply use the determination of our sources: U.S. government agencies.

Since most of this data is in the public-domain, what value are you adding?

We've spent countless hours: downloading, merging, cleaning, formatting, and aggregating this data into an accurate and concise product.

What am I allowed to do if I purchase the Comprehensive Database license?

A license allows you to use the database internally or to query the database for public-facing applications that you or your organization owns or develops. Attribution is not required. You are not allowed to publicly redistribute the database without prior permission. You can make copies of the database for internal and backup purposes. To learn more, read the full license terms.

Why should I trust this data?

This database was aggregated from authoritative sources and carefully processed by SimpleMaps. We've been developing and selling interactive maps to Fortune 500 companies and prominent international organizations for over 10 years. Over this time, we've learned a lot about geographic data. Our data products have been used in production by well-regarded organizations such as The Guardian. To get a sense of the expertise, check out some of the testimonials from our happy customers.

How do I calculate the distance between two cities?

Can I get the Pro or Comprehensive Database in Excel or SQL server?

The Comprehensive Database can be downloaded in CSV or SQL (MySQL) format upon purchase. The database has too many rows to fit in a single Excel worksheet, but we can provide the data in Excel format, broken out by country, upon request. We can also provide the data as a .bak file for SQL server. Please contact us to receive the data in one of these formats.

What's the fastest way to import the comprehensive database into MySQL?

We recommend using the CSV file and following our tutorial on importing a CSV into MySQL.

Can I purchase additional updates?

Yes. After updates expire, you can purchase 12 more months of updates for $99 (Pro) or $199 (Comprehensive).

What is the difference between the Pro and Comprehensive databases?

The main difference between the two is that the Pro database generally only includes cities and towns that either have a ranking of 1, 2, or 3 while the Comprehensive database includes all cities and towns for which we have data. For most users, the Pro database is sufficient and will be faster to query.


Cities on the Equator and the Prime Meridian

While much of the worth is solidly within hemisphere quadrants, there are many cities that straddle one of the zero points. These cities, by definition, must be either along the equator or the prime meridian (i.e., have a similar longitude to London).

The map shows 22 cities that are within two and a half degrees of the equator. You can find them by using the grouping function in the lower left corner of the map. Choose “Near Latitude” and then choose the 5 to -10 range. Or, search the map for “0” and choose “0 (Near Latitude).”

Macapá, Brazil Quito, Ecuador Padang, Indonesia Libreville, Gabon Kampala, Uganda

To get even more specific, we narrowed down to 11 cities that are less than a degree away from Earth’s horizontal midpoint. The closest to the equator is Pontianak in Indonesia, whose city center is within one second (1/60th of a degree) of zero degrees latitude.

Here are all 11 of the places within a degree of the equator:

  • Macapá, Brazil
  • São Tomé, São Tomé and Príncipe
  • Libreville, Gabon
  • Entebbe, Uganda
  • Kampala, Uganda
  • Pekanbaru, Indonesia
  • Quito, Ecuador
  • Kismayo, Somalia
  • Padang, Indonesia
  • Pontianak, Indonesia
  • Yaren District, Nauru

Since zero longitude is within densely populated Europe, there are more places that are close to this human-created coordinate. The closest, of course, is London—or Greenwich, specifically. There are 44 cities on the map that are closest to 0 longitude. Yet, there are only a dozen that are less than one degree from zero.

Greenwich, England Accra, Ghana Valencia, Spain Bordeaux, France Le Havre, France

Here are all 12 places within a degree of the prime meridian:

  • Accra, Ghana
  • Tamale, Ghana
  • Zaragoza, Spain
  • Valencia, Spain
  • Lleida, Spain
  • Bordeaux, France
  • Brighton and Hove, England
  • London, England
  • Greenwich, England
  • Le Havre, France
  • Cambridge, England
  • Peterborough, England

A much less populated place? The opposite of the prime meridian. At either 180 or -180 (it’s the same place), you’ll find just two places. One is far north and another in the south: Rabi Island, Fiji Anadyr, Russia. Move the map around and see if you can find them!


Time Zone Location Web Services

Raw Time Zone Boundary Data

    - builds time zone shapefiles from OpenStreetMaps map data. Includes territorial waters near coastlines.

The following projects have previously been sources of time zone boundary data, but are no longer actively maintained.

Time Zone Geolocation Offline Implementations

Implementations that use the Timezone Boundary Builder data

    - JavaScript library (Node.js only) - JavaScript library - JavaScript library - .NET library - PHP library - Python library - C library - Java library - Java and Android library - R library - Go library - Go library - docker container wrapping node-geo-tz

Implementations that use the older tz_world data

    - Go library (Read this post also.) - Java library - JavaScript/Node library - Python library - Ruby library - Java and Swift libraries - Blog post describing PHP and MongoDB - R library

Libraries that call one of the web services

    - Ruby gem that calls GeoNames has its own libraries for calling from Java or .Net has client libraries for just about everything

Self-hosted web services

Other Ideas

Please update this list if you know of any others

Also, note that the nearest-city approach may not yield the "correct" result, just an approximation.

Conversion To Windows Zones

Most of the methods listed will return an IANA time zone id. If you need to convert to a Windows time zone for use with the TimeZoneInfo class in .NET, use the TimeZoneConverter library.

Don't use zone.tab

The tz database includes a file called zone.tab . This file is primarily used to present a list of time zones for a user to pick from. It includes the latitude and longitude coordinates for the point of reference for each time zone. This allows a map to be created highlighting these points. For example, see the interactive map shown on the moment-timezone home page.

While it may be tempting to use this data to resolve the time zone from a latitude and longitude coordinates, consider that these are points - not boundaries. The best one could do would be to determine the closest point, which in many cases will not be the correct point.