KML coordinates are off in a custom Google Map? - google-maps

EDIT: Turns out it was all because the coordinate translation functions in the javascript were written wrong. The author of the program has apparently fixed it.
I'm trying to use KML files to display placemarks on a custom Google Maps map. The map was generated by a Minecraft mapping program called Unmined.
My problem lies with the positioning of placemarks. They are placed on the map in a position that doesn't seem to correlate with either the pixel or latitude/longitude coordinates of the map itself.
Here is an image showing my problem.
I loaded a KML with five placemarks defined. One in the middle (0,0), one in the top-left corner (-170,80), one in the top-right corner (170,80), one in the bottom-left corner (-170,-80), and one in the bottom-right corner (170,-80). The set of markers seems to be duplicated horizontally but from my experience that's standard with Google Maps. As far as I know, the range of valid coordinates in a KML file are from -180 to 180 longitude and -90 to 90 latitude, which means that any valid placemark would have to fall somewhere inside that rectangle. Except that rectangle barely intersects the map at all.
If you need access to the code I'm using, everything can be found in the source of http://tonyfox.ws/dt/kantomap/ (URL may not exist forever)
So am I just doing something catastrophically wrong or what?
On a related note, how does Google Maps decide where to place the map in the coordinate system when the map isn't an actual Earth map (like this Minecraft world map)? My map seems to range from about 14.5 to 19.5 longitude, and 25.5 to 28 latitude. Why such weird numbers?

Related

Google Maps draw area / shape / region and export as latitude longitude

I need a Google Map with marked up areas with different colors.
GADM data
The first article I came across was this one:
https://ourcodeworld.com/articles/read/830/how-to-highlight-an-area-city-state-or-country-in-google-maps-with-javascript
It links to this service for getting coordinates:
https://gadm.org/download_country_v3.html
The problem is that there are too many points so it would end up with 3MB for an embedded map.
Google Maps draw
Then I tried Google Maps service to draw a shape. While it works, I could not find any export function to get the longitude and latitude.
https://www.google.com/maps/d/u/0/viewer?mid=1IlydZDXB-tkN8K8pAR57BRFqBOTv3c8z&ll=59.681023024095936%2C18.40997752499993&z=9
Question
How can I draw an area on a map and then get longitude and latitude for the points? On Google Maps, a tool or something else does not matter.
I solved my problem very differently. I simply used an svg file of just the country and highlighted areas there.
I used this site:
https://simplemaps.com/custom/country

Get alle coordinates within an area - Google Maps

I've made a website using the geolocation API, which shows if you're in Berlin or not. To get alle the coordinates I've selected Berlin in Google Maps and downloaded a KML file with these coordinates.
Now I would like to have all the coordinates within that selection, because in the KML file are only the coordinates of the border.
Is this possible?
Get all the coordinates within an area doesn't make sense because there are literally infinite coordinates within a polygon (depending on the resolution of your coordinates of course).
What you need is to check wheter a given point is contained within a polygon. You can do it using the containsLocation() method (see the documentation)

generate layers for maps (Google or OpenLayers)

I'm trying to develop a software that gets data from a text file and generates a map layer. The map later on is going to be cut into tiles and used as overlay for Google Maps API or OpenLayers.
The data stored in the text file is weather data. The file has data about 1 x 1 squares. For example: there is .9 chance of rain for lat 1-2 and lon 5-6. I have to use the data provided in the data file and can't use pre-generated layers.
I generate the map by dividing a background white PNG into 360 horizontal boxes and 180 vertical ones and color each one based on the data available in the text file.
My problem is the fact that there are 180 latitudes and 360 longitudes but the base map for OpenLayers and Google Maps is a square. In other words, number of latitudes equals the number of longitudes in OpenLayers and Google Maps. Moreover when I take a world map and stretch it vertically the lines do not align at all.
Example:
OpenLayer base map (256px x 256px):
Generated layers (256px x 256px):
When I add the layer on top of the base map. Continents don't match. I don't have this problem when i use a non-square(256px x 128px) base map.
My question is how should I generate my layover so it works with a square world map that is being used by Google and OpenLayers?

How to convert x/y coordinates from a 2D pixel map into LatLng Values of Google Maps

yesterday I discovered the Google Maps API v3. We were searching for a good way to display a 2D map on a website. Before we never used it for anything so I would say I am totaly new to this :P
The 2D map I am talking about shows a fictive place and is 7150 x 11000 pixels. We converted it into 256 x 256 tiles and uploaded it to our test website.
We have a bunch of coordinates on this map and we searched and searched but we do not find a straight forward written description how to convert this values to LatLng values to use them for markers ...
Can anybody tell us how this works?
We were able to use the example I posted in my comment to create a projection that is mostly able to translate our x/y image coordinates to Google Map API v3.
The example shows how to translate to a Image that measures 50x50 pixel and we just had to translate this.
Because our map has no square shape we hat to add an offset to the y values and correct the x values by a correction factor.
It seems that Google Map API can only handle LatLng values up to some kind of maximum so we hat to choose a smaller size for our projection and wrote a function to translate from original size to this new fictive size which produced LatLng values the API can handle.

How to translate mercator map coordinates to relative screen coordinates?

I have a database with various map locations (latitude, longitude).
I've been using a map api (e.g. google maps) to plot these locations.
I am now experimenting to see if I can totally remove dependency of map apis and simply replace the map control with an image (an .png image).
Question:
How can I translate the map locations to be displayed properly onto this map image?
More details:
Basically, the map will be a rectangular area (i.e. Div element), where the top-left corner of the rectangle is obviously (0, 0). So basically the map locations will be displayed with respect to this top-left corner.
First off, where are you getting your geocodes from? If they are from Bing or Google Maps then you can only use those coordinates with those map controls. Using this coordinates without the map controls is against the terms of use of these API's. Assuming that these coordinates come from somewhere else you can overlay them on an image by first knowing some information about the image. At a minimium you will need to know two coordinates on the image and their relative pixel locations. From that you can then determine the scale and top left coordinate of the image. With this you can then fairly accurately position coordinates on the image using a lot of math. You can find a lot of useful math for this here: http://msdn.microsoft.com/en-us/library/bb259689.aspx I've writing a few blog posts on this a while back which you can find here: http://rbrundritt.wordpress.com/2008/10/25/ve-imagery-service-and-custom-icons/
If these coordinates come from Bing Maps you can easily display them on a map image using the Bing Maps Imagery Service: http://msdn.microsoft.com/en-us/library/ff701724.aspx