How to transfer coordinate from EPSG:3857 to GCJ-02? - coordinates

I needed TomTom's map display API in the application of Gaode Map, but I found that there was coordinate offset, which was caused by the different coordinate system used by the two companies. I wonder if there is any solution.
tomtom use EPSG:3857
Gaode map use GCJ-02

Related

How to get X and Y indexes of the current tile in Mapbox GL JS?

I'm using Mapbox GL JS to display a map using my own tile-server (which just serves openmaptiles pbf files in a Z/X/Y directory structure).
The loading of tiles is done automatically, based on the current center coordinates.
I want to pre-load the surrounding tiles for an offline solution.
I know how to get the current zoom-level with map.getZoom()
How can I get the X and Y indexes of the current tile URL ?
I suggest framing the problem in terms of geographic coordinates:
You can get the viewport geographic coordinates from Map#getBounds)
You can convert geographic coordinates to tile coordinates with some light math
Also, if you need to do some calculations in bash scripts, you can use mercantile library or CLI utility to transform lon/lan coordinates to tiles, find parent or children tiles and get some other information. Another advanced tool is supermercado.

Framework for plotting latitude longitude in a map based on country, state and district depending on the zoom level

I need a framework which takes a set of latitude longitude points and plots on a world map, grouped by country having the count of points as a marker on each country. Grouping here is the count of latitude longitude points in a country.
And as I drill down into a country, the clustering should change to state based one. And the next level, to districts.
Leaflet marker cluster is something very similar to what I have asked for, but the grouping is based on proximity and it doesn't consider country or state boundaries. That is, they are not region aware.
Regionbound.com has tweaked in some code in the leaflet code for making it region aware,
Sample marker definition:
var marker1 = new L.marker([-37.8, 145], {regions: ["Asia-Pac", "Australia", "VIC", "Melbourne"]} );
But the sample code says, every latitude longitude must be defined along with some extra parameter containing place information.
I could get the place information using reverse geocoding, but reverse geocoding every latitude longitude is time consuming right.
Highmaps provided by Highcharts is one another solution, but there, every country has code which should be assigned a value[count of point coordinates belonging to that country].
But all I have is latitude longitude points, no country or state information.
Thus, I need something which takes only a set of latitude longitude and does clustering based on country, state, district depending on the zoom level.
You have 2 separate needs in your questions:
Map your lat/lng coordinates to appropriate administrative areas. E.g. through the reverse geocoding that you mention.
Display "clusters" on those administrative areas depending on zoom level.
As for point 1, you know that lat/lng points do not say by themselves which administrative area(s) they belong to. So "reverse geocoding every latitude longitude" is a mandatory step. Whether time consuming or not depends on the solution you choose to perform this operation.
If I understand correctly, you would like a "framework" that could do that automatically for you. But frameworks are usually data agnostic, and if they do not have data about boundaries of those administrative areas, they cannot help you.
You may rather look for "services" (like the Mapbox Geocoding API that you mention) or software that would already have such data. It is not time consuming if you can program the lookup (or perform "bulk" operations) and if you are not limited by the requests rate and your amount of points to map (which may be the case with Mapbox).
You could very well set up your own application to perform this mapping:
As for the dataset for administrative areas boundaries, you would probably be interested in links in this post: Are there any free administrative boundaries available as shapefiles? If your points are limited to a few countries, it will be easier for you to find the appropriate data source(s).
Once you have that data, many GIS software should be capable of mapping your lat/lng points to the areas they belong to. This would be mainly for a "one-shot" operation, if your set of points do not change much.
A "web-compatible" alternative would be for example to use Leaflet with point in polygon for Leaflet plugin. You would need your boundaries data converted to GeoJSON format first. Again, GIS software should be capable of doing so, or many online services as well (search for "convert geojson" for example).
A server-side solution would avoid having to manage the entire boundaries data through network and in client browser (if you need to perform the mapping dynamically). I am sure many GIS servers are capable of performing this operation, once they are fed with the boundaries data.
For point 2, once you have completed the above step, I think you would have many options available, including those you mention (RegionBound, Highmaps).
Even with standard mapping libraries (Leaflet, OpenLayers 3), you would just need to build your "clusters" (markers on administrative areas with a number saying how many points are in there), like you have to do with Highmaps anyway for example.
Computing the number of "clustered" point is as easy as filtering your points per area name / code. Then switch the clusters to the desired administrative level when the map zoom changes.
So the key is really to determine first to which areas your points belong to (point 1).
Then a small question would rise about where to place the "cluster" marker:
On centroid of the administrative area? You need the coordinates of that centroid from your data source, or a good algorithm to compute it from the boundaries (good luck on that…).
On "center" of the bounding box of the area? Leaflet can easily compute that: from your area vector shape, you would do myShape.getBounds().getCenter().
On barycentre / centroid of the clustered points? This is what Leaflet.markercluster and RegionBound do (do not know for Highmaps).
Good luck!

Find adjacent tiles in bing maps

I am grabbing maps from bing using their API:
http://msdn.microsoft.com/en-us/library/ff701724.aspx
The largest tile they can return is 900x834. I need at least double that. Is there an easy way to figure out what the adjacent tiles are for any given zoom level and long/lat for a given resolution.
In other words, given a long,lat, zoom level, and resolution what would be the long lat for the 8 surrounding tiles in the same zoom level and resolution. Or is there a better way to get a large map?
Here's my GET request:
http://dev.virtualearth.net/REST/v1/Imagery/Map/Aerial/#{lat},#{long}/#{rand(19)}?mapSize=900,834&format=png&key=MYKEY
It is not possible to do this without breaking the rules set in the Terms of Use, especially the automation regarding your imagery retrieval (or composition).
See: http://www.microsoft.com/maps/product/terms.html
If you want to do this anyway with maybe a dedicated agreement to proceed (if possible), I would recommend to use mapArea parameters rather than using the lat long of the center, see:
http://msdn.microsoft.com/en-us/library/ff701724.aspx
See an example of mapArea imagery retrieval:
http://dev.virtualearth.net/REST/V1/Imagery/Map/road?mapArea=37.317227,-122.318439,37.939081,-122.194565&ms=500,600&pp=37.869505,-122.2705;35;BK&pp=37.428175,-122.169680;;ST&ml=TrafficFlow&key=BingMapsKey
If you want to access tile url in a supported way, you can use the same imagery service to retrieve metadata that will contain tile url. Tile are based on a quadkey model so you will be able to load the tile nearby your current view.

What is the projection used by MKMapView?

I am storing a number of point features inside a SQLite database for display inside of MKMapView and I would like to precompute and store coordinates in the the projection of the map instead of in lat/lon (for index/performance reasons). However, I am creating this database externally (in Python), so I cannot simply use the MKMapPointForCoordinate() function. What is the projection used by MKMapView? The documentation states that it is a mercator projection but it does not appear to be the web mercator projection that I expected. How can I compute an X/Y coordinate from a Lat/Lon ?
Personally I feel you're approaching the problem from the wrong angle - you say don't want to store latitude/longitude co-ordinates for 'index/performance reasons'. What are these reasons?
Storage, indexing, and querying of geographic coordinates inside of a database is not an unusual problem. They are simply two decimal numbers, making indexing and querying very straightforward.
Apple also tell you only to save co-ordinates rather than MKMapPoints in their own documentation:
When saving map-related data to a file, you should always save coordinate values (latitude and longitude) and not map points.
Perhaps you could share some of the issues you're having saving co-ordinates to a database?
I'm pretty sure it is webmercator because the overlay tiles I have produced are in that projection and they fit. But like other conmenters said, you're advised to store them in lat/long. If you want to query results in a grid lat/long provide a pretty good starting point. The grid isn't square as you leave the equator but it is rectangular.

google earth model transformation

I would like to add placemarks to parts of collada geometry in google earth. To do this I need to translate the geometry coordinates in the xml to match the transformation to the model in google earth. Given longitude latitude and orientation how do I translate geometry coordinate to match the google earth transformation?
I believe models are located on the earth using only 1 coordinate which is used to position the 'center' of the model. How that is determined I am not sure, and might even depend on the kind/shape of the model.
The coordinate is easily found in the kml structure for the model which is referenced here
http://code.google.com/apis/kml/documentation/models.html
Determining how far a certain part of your geometry is from the middle might be very complex but here is an example of some code that will provide you the distance between two points.
http://earth-api-utility-library.googlecode.com/svn/trunk/extensions/examples/ruler.html
It is based upon the google earth extensions (gex) library
http://code.google.com/p/earth-api-utility-library/
Perhaps you could use SketchUp to help determine the location of your points of interest within the geometry?
http://sketchup.google.com/