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。
答案 0 :(得分:0)
是的,确实如此。您需要在其用户记录中保留其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>
如果他们的APi密钥为空,那么在你的Getter中可能值得,然后切换你的默认值。