javascript - Google map failed to load - Stack Overflow

I need to integrate a google map in my web page. I generated a API. But the map is not displaying. I am

I need to integrate a google map in my web page. I generated a API. But the map is not displaying. I am testing it in my local server.

<h3>My Google Maps Demo</h3>
<div id="map">
    <span class="labels">Heading</span>
</div>
<script  src="=[API]&callback=initMap">
</script>
<script type="text/javascript">
    function initMap() {
                alert("Yes");
                var uluru = { lat: -25.363, lng: 131.044 };
                var map = new google.maps.Map(document.getElementById('map'), {
                    zoom: 4,
                    center: uluru
                });
                var marker = new google.maps.Marker({
                    position: uluru,
                    map: map
                });
            }
</script>

but no use. Is their any issue in my code? Can i check my API is working or not

I need to integrate a google map in my web page. I generated a API. But the map is not displaying. I am testing it in my local server.

<h3>My Google Maps Demo</h3>
<div id="map">
    <span class="labels">Heading</span>
</div>
<script  src="https://maps.googleapis./maps/api/js?key=[API]&callback=initMap">
</script>
<script type="text/javascript">
    function initMap() {
                alert("Yes");
                var uluru = { lat: -25.363, lng: 131.044 };
                var map = new google.maps.Map(document.getElementById('map'), {
                    zoom: 4,
                    center: uluru
                });
                var marker = new google.maps.Marker({
                    position: uluru,
                    map: map
                });
            }
</script>

but no use. Is their any issue in my code? Can i check my API is working or not

Share Improve this question edited Oct 27, 2017 at 6:39 K K 18.1k4 gold badges32 silver badges39 bronze badges asked Oct 27, 2017 at 6:27 JksJks 1031 gold badge2 silver badges19 bronze badges 2
  • 1 Forgive my impertinence, but isn't that JS, not C#? – ProgrammingLlama Commented Oct 27, 2017 at 6:33
  • 2 @john Java != JavaScript. Oh wait... Maybe he thinks that C# is Java and Java is JavaScript! – DogeAmazed Commented Oct 27, 2017 at 6:38
Add a ment  | 

4 Answers 4

Reset to default 3

I cannot ment, so I write here. Do you have key code?

In console, there are errors:

RefererNotAllowedMapError Error
The current URL loading the Google Maps JavaScript API has not been added to the list of allowed referrers. Please check the referrer settings of your API key on the Google API Console.

See API keys in the Google API Console. For more information, see best practices for securely using API keys.

Maybe this would help you.

You need to have api key to access the maps. Modify your code like this:

JS:

 function initMap() {
   alert("Yes");
   var uluru = {
     lat: -25.363,
     lng: 131.044
   };
   var map = new google.maps.Map(document.getElementById('map'), {
     zoom: 4,
     center: uluru
   });
   var marker = new google.maps.Marker({
     position: uluru,
     map: map
   });

 }
 google.maps.event.addDomListener(window, "load", initMap);

Check this demo: http://jsfiddle/lotusgodkk/hLenqzmy/64/

You can get the api key from here: https://developers.google./maps/documentation/javascript/get-api-key

Your code is working fine. You need to place a JavaScript Google API there (I guess you placed another Google Maps Key)

Also check out this link for some google examples

Also, initMap will be called while the page is loading, and MIGHT not have been declared at the time it was called?

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745657163a4638611.html

相关推荐

  • javascript - Google map failed to load - Stack Overflow

    I need to integrate a google map in my web page. I generated a API. But the map is not displaying. I am

    21天前
    50

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信