[英]It is possible to give different Google API Key in ASP.NET Google maps Application?
I am using googlemaps.subgurim.net in my application,it is possible to set different GOOGLE API KEY to different users based on their logins.
web.config:
<add key="googlemaps.subgurim.net" value="xxxxxxxxx"/>
.aspx:
<cc1:GMap ID="GMap1" runat="server" Height="805px" Width="800px" />
.aspx.cs:
string sMapKey = ConfigurationManager.AppSettings["googlemaps.subgurim.net"];
GeoCode objAddress = new GeoCode();
objAddress=Map.geoCodeRequest(newGLatLng(Convert.ToDouble(status.Rows[0][0]),Convert.ToDouble(status.Rows[0][1])), sMapKey);
StringBuilder sb = new StringBuilder();
if (objAddress.valid)
{
sb.Append(objAddress.Placemark.address.ToString());
lbladd.Text = sb.ToString();
}
我在應用程序中使用googlemaps.subgurim.net,可以根據不同的用戶登錄名將其設置為不同的GOOGLE API KEY。
是的。 您將需要在其用戶記錄中保留其API密鑰,例如在數據庫中,然后在Api腳本中只需切換變量
網絡表格
<script type="text/javascript"
src="https://maps.googleapis.com/maps/api/js?key=<%=User.ApiKey%>&sensor=SET_TO_TRUE_OR_FALSE">
</script>
MVC
<script type="text/javascript"
src="https://maps.googleapis.com/maps/api/js?key=@Model.UserApiKey&sensor=SET_TO_TRUE_OR_FALSE">
</script>
在Getter中值得一提的是,如果他們的APi密鑰為null,則請使用默認值。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.