title: InvalidKeyOrUnauthorizedURLMapError Google Maps API v3
body: <p>I am developing in JavaScript/ASP.NET an app that uses Google Maps. I am getting the following alert dialog box:</p>
  
  <blockquote>
    <p>"This page was unable to display a Google Maps element. The provided
    Google API key is invalid or this site is not authorized to use it.
    Error Code: InvalidKeyOrUnauthorizedURLMapError"</p>
  </blockquote>
  
  <p>This alert comes after I made the marker in the map from my localhost database. Before the map connect to the database, everything is working fine.</p>
  
  <p>This is the javascript code :</p>
  
  <pre><code>private static string SetSourceScript()
      {
          StringBuilder sb = new StringBuilder();
  
          string markers = ProductAllLocationCatalog.GetAllLocation();
  
          sb.Append("&lt;script type='text/javascript' src='https://maps.googleapis.com/maps/api/js?v=3&amp;key=MYKEY&amp;sensor=false' runat='server'&gt;&lt;/script&gt;");
          sb.Append("&lt;script type='text/javascript'&gt;                                                       ");
          sb.Append("   function initialize() {                                                            ");
          sb.Append("     var mapOptions = {                                                               ");
          sb.Append("        center : new google.maps.LatLng(-6.9027117, 107.6037877),                     ");
          sb.Append("        zoom : 9,                                                                     ");
          sb.Append("        mapTypeId: google.maps.MapTypeId.ROADMAP                                      ");
          sb.Append("     };                                                                               ");
          sb.Append("     var myMap = new google.maps.Map(document.getElementById('map-canvas'),mapOptions);" + markers + "}");
          sb.Append("google.maps.event.addDomListener(window, 'load', initialize);                         ");
          sb.Append("&lt;/script&gt;                                                                             ");
          //sb.Append("&lt;script src='../js/MapScript.js' runat='server'&gt;&lt;/script&gt;");
  
          return sb.ToString();
      }
  
      public static string GetSourceScript()
      {
          return SetSourceScript();
      }
  
  &lt;!--Code to call the map :--&gt;
  &lt;div id="map-canvas" style="width: 100%; max-width: 950px; height:400px; text-align:center;"&gt;&lt;/div&gt;
  </code></pre>
  
  <p>And this is how I get Latitude and Longitude from database :</p>
  
  <pre><code>public static string GetAllLocation()
      {
          SqlConnection conn = GetConnection();
          StringBuilder sqlCmd = new StringBuilder();
          string markers = "";
          sqlCmd.Append("SELECT Lat, Lng, City FROM csr");
  
          SqlCommand cmd = GetCommand(conn, sqlCmd.ToString());
  
          try
          {
              conn.Open();
              DataTable data = new DataTable();
              SqlDataReader reader = GetDataReader(cmd);
              int i = 0;
              while (reader.Read())
              {
                  i++;
                  markers +=
                      @"var marker" + i.ToString() + @" = new google.maps.Marker({" +
                          @"position : new google.maps.LatLng(" + reader["Lat"].ToString() + ", " + reader["Lng"].ToString() + ")," +
                          @"map : myMap, title:'" + reader["City"].ToString() + "'});" +
                      @"google.maps.event.addListener(marker" + i.ToString() + @",'click',function(marker" + i.ToString() + "," + i + ") {" +
                          @"return function() {" +
                              @"infowindow.setContent('" + reader["City"].ToString() + "');" +
                              @"infowindow.open(map, marker" + i.ToString() + ");" +
                          "}" +
                      @"})(marker" + i.ToString() + "," + i + "));";            
              }
              return markers;
          }
          finally
          {
              conn.Close();
          }
      }
  </code></pre>
  
  <p>Please help~~ Thank you!</p>
  
  <p>By the way, I already set my api key, so it allow my IP Address and the references set to localhost/*</p>
  
  <p>The marker from database is working fine. I could tell that because the map will dissapear after two seconds. So I already saw that the markers is there perfectly.</p>
  
  <p>And, do I have to use Google Map for Work if I want the marker is from my database? Also how if I want this map can be accessed from many computers?</p>