title: TileProvider method getTile - need to translate x and y to lat/long
body: <p>I’m porting an iOS app to Android, and using <code>Google Maps Android API v2.</code>  The application needs to draw a heatmap overlay onto the map.</p>
  
  <p>So far, it looks like the best option is to use a <code>TileOverlay</code> and implement a custom <code>TileProvider</code>.  In the method <code>getTile</code>, my method is given x, y, and zoom, and needs to return a bitmap in the form of a <code>Tile</code>.  So far, so good.  </p>
  
  <p>I have an array of heatmap items that I will use to draw radial gradients onto the bitmap, each with a lat/long.  I am having trouble with the following two tasks:</p>
  
  <ol>
  <li>How do I determine if the tile represented by x, y, and zoom contains the lat/long of the heatmap item?</li>
  <li>How do I translate the lat/long of the heatmap item to x/y coordinates of the bitmap.</li>
  </ol>
  
  <p>Thank you for your help!</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>Thanks to MaciejGórski's answer below, and marcin's implementation I was able to get the 1st half of my question answered, but I still need help with the 2nd part.  To clarify, I need a function to return the x/y coordinates of the tile for a specified lat/long.  I've tried reversing the calculations of MaciejGórski's and marcin's answer with no luck.  </p>
  
  <pre><code>public static Point fromLatLng(LatLng latlng, int zoom){
      int noTiles = (1 &lt;&lt; zoom);
      double longitudeSpan = 360.0 / noTiles;
      double mercator = fromLatitude(latlng.latitude);
      int y = ((int)(mercator / 360 * noTiles)) + 180;
      int x = (int)(latlng.longitude / longitudeSpan) + 180;
      return new Point(x, y);
  }
  </code></pre>
  
  <p>Any help is appreciated!</p>