Eray Tuncer
Eray Tuncer

Reputation: 725

Marking Google Static Maps via Google Places API

Guys I am new at this map things and it works very well individually. I have understood many concepts and etc. However, I have stuck at the point that I have no idea how to mark places fetched via API on the static maps.

Here is a lovely http request for a static map:

https://maps.googleapis.com/maps/api/staticmap?center=40.75901,-73.98447&zoom=17&scale=2&size=640x640&maptype=roadmap&markers=color:green|label:C|40.75901,-73.98447

Let me go a bit detailed. I try to make them work on Unity 5 and save that response as texture to put into a 3d model. This is the result:

Engine Inside Result

So far so good but I cannot go beyond. Lets say I want to get bus stops and put 3d bus station models onto the map. I can get the coordinates of the stations on the area. Now, how can I put a 3d model onto the red circle?

Can you guys lead me to a solution?

PS: I have encountered a term "mercator projection" but I couldnt inject it into my project :S

Upvotes: 0

Views: 747

Answers (1)

Soldeplata Saketos
Soldeplata Saketos

Reputation: 3461

I suggest you to follow these steps:

  1. Knowing the bounds of the map: NorthEast and SouthWest Coordinates of your map.
  2. Knowing the size of the map: in this case you set 640x640.
  3. Make a function that transforms the coordinates of the bus stop in the real world into your map coordinates.

Example:

  • Your bounds are: NE (91.5, 12.7) and SW (87.3, 8.4).
  • Your picture of the map is 600x600 pixels. It means that if (0,0) in your picture corresponds to the top-left corner, or NW = (91.5, 8.4).
  • The width of your picture is 600 and it goes from West to East that is (12.7 - 8.4) = 4.3, meaning that every pixel covers 4.3/600 ~= 0.00716666666667 units in the coordinates.
  • Let's say we have a point in coordinates (88.37, 10.125) and we want to calculate in which pixel goes the Longitude coordinate: ((10.125 - 8.4) / (12.7 - 8.4)) * 600 = 241 pixel.

Do the same for the Latitude and you have it. Easy, right?

Upvotes: 1

Related Questions