我想尝试一个实现Gmaps v3的示例演示,并从Google的文档中尝试了这个示例,但没有输出,页面只加载几秒钟然后空白,没有输出.
<!DOCTYPE html>
<html lang = "en">
<head>
<style type="text/css">
html{height: 100%}
body{height: 100%; margin: 0; padding: 0}
#map-canvas{height: 100%}
</style>
<title>GMaps Demo</title>
<script src = "https://maps.googleapis.com/maps/api/js?
key=${API_KEY}&sensor=false">
</script>
<script>
function initialize(){
var mapOptions = {
center: new google.maps.LatLng(-34.397, 150.644),
zoom: 8,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = google.maps.Map(
document.getElementById("map-canvas"),
mapOptions);
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>
<body>
<div id = "map-canvas">
</div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud) 嗨,我正在使用此代码在谷歌地图中使用get-directions.但是当我从其他机器运行它时,它显示错误无效的api密钥.如何在没有api密钥的情况下使用同一个地图.
<script src="http://maps.google.com/maps?file=api&v=2&sensor=false&key=ABQIAAAAuPsJpk3MBtDpJ4G8cqBnjRRaGTYH6UMl8mADNa0YKuWNNa8VNxQCzVBXTx2DYyXGsTOxpWhvIG7Djw" type="text/javascript"></script>
<style type="text/css">
body {
background:#FFE1C7;
font-family: Verdana, Arial, sans serif;
font-size: 11px;
margin: 2px;
}
table.directions th {
background-color:#EEEEEE;
}
img {
color: #000000;
}
</style>
<script type="text/javascript">
var map;
var gdir;
var geocoder = null;
var addressMarker;
function initialize() {
if (GBrowserIsCompatible()) {
map = new GMap2(document.getElementById("map_canvas"));
gdir = new GDirections(map, document.getElementById("directions"));
GEvent.addListener(gdir, "load", onGDirectionsLoad);
GEvent.addListener(gdir, "error", handleErrors);
setDirections("Bangalore", "Mysore", "en_US");
}
}
function setDirections(fromAddress, toAddress, locale) {
gdir.load("from: " + fromAddress + " to: …Run Code Online (Sandbox Code Playgroud) 我正在开发使用Google地图的JavaScript/HTML/CSS应用程序.我收到以下警告对话框:
"此页面无法显示Google地图元素.提供的Google API密钥无效或此网站无权使用它.错误代码:InvalidKeyOrUnauthorizedURLMapError"
该应用不实际显示在地图元件; 警报不是问题,除非它根本不应出现.地图显示正确.
我已进入Google开发人员控制台,在"凭据"部分中,已将"已编辑的允许引荐来源"设为mydomain.com/*
我还在API部分访问了Google Developer's Console,并启用了11个Google Maps API.
我有一个API密钥.它是"浏览器应用程序的关键(带有引用者).它工作正常,但当我尝试在我的本地开发服务器上使用它时,我没有被授权.我使用MAMP,我的本地URL如下所示:http://mysite.dev.
在"Referers"部分,我有:
mysite.com/*
mysite.dev/*
Run Code Online (Sandbox Code Playgroud)
制作一个(.com)工作正常,所以我很确定我的语法是正确的.但无论我尝试使用本地版本,我都会收到Google的授权错误信息,告诉我:
Google已禁止将Maps API用于此应用程序.提供的密钥不是有效的Google API密钥,也未授权此网站上的Google Maps Javascript API v3.如果您是此应用程序的所有者,则可以在此处了解如何获取有效密钥:https: //developers.google.com/maps/documentation/javascript/tutorial#api_key
肯定有办法让这个工作!它是什么?
我试图用Ionic谷歌地图实现地图.我按照这个链接的编码 但我得到的是一个空白屏幕不知道我哪里出错了.请帮忙
这是控制器
angular.module('starter', ['ionic'])
.controller('MapCtrl', function($scope, $ionicLoading, $compile) {
function initialize() {
var myLatlng = new google.maps.LatLng(43.07493,-89.381388);
var mapOptions = {
center: myLatlng,
zoom: 16,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map"),
mapOptions);
//Marker + infowindow + angularjs compiled ng-click
var contentString = "<div><a ng-click='clickTest()'>Click me!</a></div>";
var compiled = $compile(contentString)($scope);
var infowindow = new google.maps.InfoWindow({
content: compiled[0]
});
var marker = new google.maps.Marker({
position: myLatlng,
map: map,
title: 'Uluru (Ayers Rock)'
});
google.maps.event.addListener(marker, 'click', function() { …Run Code Online (Sandbox Code Playgroud) 最近谷歌改变了使用API密钥的政策.您现在不再需要API密钥才能在您的网站上放置Google地图.
这非常有效.但是现在我在我的localhost上运行了这张地图(没有API密钥),这很好用.但是当我把它放在网上时,我会得到一个弹出窗口,说我需要另一个API密钥.在该网站的另一个页面上,Google地图确实有效.它可能与某些事情有关吗?不起作用的地图上有很多(30+)标记吗?
实际上使用API密钥对我来说不是一个很好的解决方案,因为这是许多网站上使用的Wordpress插件的一部分.
以这个例子为例 - http://jsfiddle.net/pborreli/X5r8r/
这是一个有效的谷歌地图示例,但在检查jsFiddle上的源代码时,没有公开相应的API密钥.
我有一个问题要问谷歌地图,为此我想做一个jsFiddle示例,但我不知道如何保持我的谷歌API密钥私密?
谢谢.