It is actually possible to place your top left corner at 0,0 and your bottom right at 50,50, if you want this. Of course you can place bottom right corner at 10,10, too, or whatever, within the limits: -90/+90 for latitude and -180/+180 for longitude.
The proportion should be:
/*
******************************************
Custom Projection - CARTESIAN
******************************************
*/
function CartesianProjection() {
// map size at zoom 0 is equal to tile size
this.tileSize = 256;
};
CartesianProjection.prototype.fromLatLngToPoint = function(latLng) {
var x = (latLng.lng() / 50) * this.tileSize;
var y = (latLng.lat() / 50) * this.tileSize;
return new google.maps.Point(x, y);
};
CartesianProjection.prototype.fromPointToLatLng = function(point, noWrap) {
var lng = (point.x / this.tileSize) * 50;
var lat = (point.y / this.tileSize) * 50;
return new google.maps.LatLng(lat, lng, noWrap);
};
Then you should place the center of the map to LatLng(25,25) in the Map options.
The reason you don't get the postal code is the query is too broad. If you would add a street name to the query the result will contain a postal code. A solution to your problem if you don't have a street name or don't want to use it is to split the geocoding into two parts:
Step 1: Use the city to get the GPS coordinates
https://maps.googleapis.com/maps/api/geocode/json?address=amsterdam
Step 2: Use the the GPS coordidates to get the postal code
https://maps.googleapis.com/maps/api/geocode/json?latlng=52.3182742,4.7288558
For those doing it in backend/script, here is a snippet: (using python Geocoder)
g = geocoder.google(city, key=google_api_key)
latlng = g.latlng
g_prime = geocoder.google("{},{}".format(*latlng), key=google_api_key)
postal_code = g_prime.postal
Best Answer
I think this is not so hard a problem to solve but I have my doubts about whether the accuracy is absolutely correct. First of all, you have to convert your center lat/lon to pixels with gdal2tiles codes. If I find some time and if you want, I can convert it to stable code for finding corner coordinates.
This is a Python code:
Then you can use addition or substraction by looking the following image:
If you want to find point A :
or you want to find point B:
and the last thing is that you have to do is convert your pixels to lat/lon.
so the result I have:
I hope it helps you....