-
Hello everyone!
I just started a small project and i wanted to use google maps along with it. I made a test page and got google maps to work just fine, but once I tried implementing it to my project, it doesn't work and i'm not sure why.
I've deleted several lines of code and nothing seems to be working. Starting to think it's because I'm using a resposnive theme website that it won't load google maps.
Any advice is greatly appreciated.
-
-
Oh ... i'm sorry ... um ... should I post the Code? or something?
-
Post a link to the site itself.
I can tell you, thought, that a responsive design by itself will have no bearing on a Google map.
-
This is what i been working with the last few days, still haven't gotten the map to load.
Code:
<!DOCTYPE html>
<!-- HTML5 Mobile Boilerplate -->
<!--[if IEMobile 7]><html class="no-js iem7"><![endif]-->
<!--[if (gt IEMobile 7)|!(IEMobile)]><!-->
<html class="no-js" lang="en">
<!--<![endif]-->
<!-- HTML5 Boilerplate -->
<!--[if lt IE 7]><html class="no-js lt-ie9 lt-ie8 lt-ie7" lang="en"> <![endif]-->
<!--[if (IE 7)&!(IEMobile)]><html class="no-js lt-ie9 lt-ie8" lang="en"><![endif]-->
<!--[if (IE 8)&!(IEMobile)]><html class="no-js lt-ie9" lang="en"><![endif]-->
<!--[if gt IE 8]><!-->
<html class="no-js" lang="en">
<!--<![endif]-->
<head>
<meta charset="utf-8">
<!-- Always force latest IE rendering engine (even in intranet) & Chrome Frame -->
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Magic Finder</title>
<meta name="description" content="Find a magic game easily!">
<meta name="keywords" content="Magic The Gathering, Trading Card Game, MTG, TCG, web design">
<meta name="author" content="Augusto Garcia">
<meta http-equiv="cleartype" content="on">
<link rel="shortcut icon" href="/favicon.ico">
<!-- Responsive and mobile friendly stuff -->
<meta name="HandheldFriendly" content="True">
<meta name="MobileOptimized" content="320">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href='http://fonts.googleapis.com/css?family=PT+Sans:400,700' rel='stylesheet' type='text/css'>
<!-- Stylesheets -->
<link rel="stylesheet" href="css/html5reset.css" media="all">
<link rel="stylesheet" href="css/responsivegridsystem.css" media="all">
<link rel="stylesheet" href="css/col.css" media="all">
<link rel="stylesheet" href="css/responsiveslides.css">
<!-- Responsive Stylesheets -->
<link rel="stylesheet" media="only screen and (max-width: 1024px) and (min-width: 769px)" href="/css/1024.css">
<link rel="stylesheet" media="only screen and (max-width: 768px) and (min-width: 481px)" href="/css/768.css">
<link rel="stylesheet" media="only screen and (max-width: 480px)" href="/css/480.css">
<!-- All JavaScript at the bottom, except for Modernizr which enables HTML5 elements and feature detects -->
<script
src="http://maps.googleapis.com/maps/api/js?key=AIzaSyCXB10peXuvlVOaYum_29bdmSmSFqIgHto&sensor=false">
</script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script src="js/modernizr-2.5.3-min.js"></script>
<script src="js/responsive-nav.js"></script>
<script>
function initialize()
{
var mapProp = {
center:new google.maps.LatLng(51.508742,-0.120850),
zoom:5,
mapTypeId:google.maps.MapTypeId.ROADMAP
};
var map=new google.maps.Map(document.getElementById("googleMap"),mapProp);
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
<style type="text/css">
html {height:100%}
body {height:100%;margin:0;padding:0}
#googleMap {height:100%}
</style>
</head>
<body>
<div id="skiptomain"><a href="#maincontent">skip to main content</a></div>
<div id="wrapper">
<nav class="clearfix">
<ul class="clearfix">
<li><a href="#">Magic Finder</a></li>
<li><a href="#">Events</a></li>
<li><a href="#">Post</a></li>
<li><a href="#">Map</a></li>
<li><a href="#">Register</a></li>
<li><a href="#">Sign In</a></li>
</ul>
<a href="#" id="pull">Menu</a> </nav>
<!--search bar-->
<form class="form-wrapper cf">
<input type="text" placeholder="Enter Address or zip code..." required>
<button type="submit">Search</button>
</form>
<div id="googleMap"></div>
<div id="maincontentcontainer">
<div id="maincontent">
</div>
</div>
<!-- More Scripts-->
<script src="js/responsivegridsystem.js"></script>
<script>
$(function() {
var pull = $('#pull');
menu = $('nav ul');
menuHeight = menu.height();
$(pull).on('click', function(e) {
e.preventDefault();
menu.slideToggle();
});
$(window).resize(function(){
var w = $(window).width();
if(w > 320 && menu.is(':hidden')) {
menu.removeAttr('style');
}
});
});
</script>
</body>
</html>
-
You're not calling the initialize() function. You're defining it, but not calling it.
Anywhere after the </div> tag for googleMap will do.
-
ok so like i said i am rather new at this, how do i call for the function?
-
what i don't understand is if i do this ...
Code:
<!DOCTYPE html>
<html>
<head>
<script
src="http://maps.googleapis.com/maps/api/js?key=AIzaSyCXB10peXuvlVOaYum_29bdmSmSFqIgHto&sensor=false">
</script>
<script>
function initialize()
{
var mapProp = {
center:new google.maps.LatLng(51.508742,-0.120850),
zoom:5,
mapTypeId:google.maps.MapTypeId.ROADMAP
};
var map=new google.maps.Map(document.getElementById("googleMap"),mapProp);
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
<style type="text/css">
html {height:100%}
body {height:100%;margin:0;padding:0}
#googleMap {height:100%}
</style>
</head>
<body>
<div id="googleMap"></div>
</body>
</html>
I get google maps working fine, but the moment i try to get it to run under my nav, it won't run ... even without calling for it.
-
Take that last line out of your script. All you need to do is this:
Code:
<div id="googleMap"></div>
<script type="text/javascript">initialize();</script>
The second line calls your initialize function.
-