user1752532
user1752532

Reputation:

Getting the location from a right click in maps, either Bing or Google

This is really troubling me a bit. I am pretty sure that this can be done but for the life of me i cannot find any documentation on this.

So often i go to google maps and all i want to do it get the address of one location and not "directions from here to here" and it was only until recently that i found bing maps has that functionality with the right click.

However now i am looking to integrate this functionality into an app using their api. I have gone over the docs and the sdk sandbox, as well as google's playgound coder sandbox and i still dont find this functionality. Bing does have a method getlocation(); but that is for lat and long and i am looking for the actual address.

I dont know but this seems like fundamental functional in a mapping service.

Upvotes: 0

Views: 580

Answers (1)

Alexander Gorelik
Alexander Gorelik

Reputation: 4385

Bing has event of right mouse click. As a result you get pixelX,pixelY coordinates(in red rectangle) of this click on the map.

You can see that here: http://www.bingmapsportal.com/isdk/ajaxv7#AttachMapEvents3

enter image description here Then by using transformation function you can get the latitude and longitude. While the "levelOfDetail" property is the zoom of the map(but i'am not shure about this one).

   public static void PixelXYToLatLong(int pixelX, int pixelY, int levelOfDetail)
        {
            double mapSize = MapSize(levelOfDetail);
            double x = (Clip(pixelX, 0, mapSize - 1) / mapSize) - 0.5;
            double y = 0.5 - (Clip(pixelY, 0, mapSize - 1) / mapSize);

            latitude = 90 - 360 * Math.Atan(Math.Exp(-y * 2 * Math.PI)) / Math.PI;
            longitude = 360 * x;
        }

The documentation of those transformations you can see here:

http://msdn.microsoft.com/en-us/library/bb259689.aspx

Upvotes: 1

Related Questions