i have a facebook app using Heroku and i use a google map for it. The google map is displayed only in Firefox Browser. Chrome an IE will not display it!
I can't understand why and i need your help!
https://apps.facebook.com/sectorsase/
<!DOCTYPE html>
<html>
<head>
<script type='text/javascript' src='http://maps.google.com/maps/api/js?sensor=false'></script>
<script>
function initialize()
{
var IPos=new google.maps.LatLng(4.256,4.568);
var mapProp = {
center:new google.maps.LatLng(44.438683,26.027269),
zoom:13,
disableDefaultUI:true,
draggable: false,
zoomControl: false,
scrollwheel: false,
disableDoubleClickZoom: true,
mapTypeId:google.maps.MapTypeId.ROADMAP
};
var map=new google.maps.Map(document.getElementById('googleMap'),mapProp);
var marker=new google.maps.Marker({
position:IPos,
icon:'icn.png'
});
var myCity = new google.maps.Circle({
center:IPos,
radius:3,
strokeColor:'#0000FF',
strokeOpacity:0.8,
strokeWeight:2,
fillColor:'#0000FF',
fillOpacity:0.4
});
myCity.setMap(map);
marker.setMap(map);
}
google.maps.event.addDomListener(window, 'load', initialize);
google.maps.event.trigger(map, 'resize');
</script>
</head>
<body>
<center><div id='googleMap' style='width:500px;height:380px;'></div></center>
</body>
</html>
IE ERROR:
SEC7111: HTTPS security is compromised by http://maps.google.com/maps/api/js?sensor=false
map.php
SCRIPT1002: Syntax error
map.php, line 17 character 33
CHROME ERROR:
[blocked] The page at https://quiet-everglades-2697.herokuapp.com/map.php ran insecure content from http://maps.google.com/maps/api/js?sensor=false. map.php:1 Uncaught ReferenceError: google is not defined map.php:49
With the errors you've provided, I'm going to assume the page you're viewing is HTTPS. You're loading the Google Maps API from a non-HTTPS source. Just change the script tag to https://maps.google.com/maps/api/js?sensor=false. Or better //maps.google.com/maps/api/js?sensor=false which will automatically fill in the http or https for you.
Related
Need your help. I have the error on my WordPress site. Google Maps shows this errors:
Jb {message: "initMap is not a function", name: "InvalidValueError", stack: "Error↵ at new Jb (https://maps.googleapis.com/m…xALxizYJSGZA470&callback=initMap&ver=4.9.5:157:51"}
And this
Uncaught TypeError: Cannot read property 'firstChild' of null
In my code.js I have this code:
(function ($) {
...
function initMap(officeLocation, pathMap) {
var map = new google.maps.Map(document.getElementById(pathMap), {
zoom: 15,
center: officeLocation
});
var marker = new google.maps.Marker({
position: officeLocation,
map: map
});
}
showOnKyivMap.on('click', function() {
mapCover.fadeIn(500);
initMap(kyivOffice, mapFooter);
});
$(document).ready(function() {
initMap(kyivOffice, mapKyivContacts);
});
})(jQuery);
Google Map script is connected in functions.php
wp_enqueue_script( 'google-maps', "https://maps.googleapis.com/maps/api/js?key=AIzaSyAN-c6nn0xMNJB_2SfGxALxizYJSGZA470&callback=initMap", array("code-js"), '', true);
So what do I do wrong?
Instead of using function to create google map, you can use <iframe> for showing google map. For using <iframe> properly use you can visit to below link:
https://en.support.wordpress.com/google-maps/
If I copy and paste the google maps api example in a html file and open the file it works:
However, if I put it in a blade file in Laravel and open it, then its not working. The window is blank and in the console I find the error
TypeError: a is null
[Learn More]
The only thing that I did was to copy and paste the content to test.blade.php and created a route
Route::get('/test', function(){
return view('test');
});
This is the content of my test.blade.php
<!DOCTYPE html>
<html>
<head>
<style>
#map {
height: 400px;
width: 100%;
}
</style>
</head>
<body>
<h3>My Google Maps Demo</h3>
<div id="map"></div>
<script>
function initMap() {
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>
<script async defer
src="https://maps.googleapis.com/maps/api/js?key=**mysupersaveapikey**&callback=initMap">
</script>
</body>
</html>
What is it that I am missing?
I recomment use dedicated api for google maps in Laravel project:
https://github.com/egeloen/ivory-google-map
use Ivory\GoogleMap\Helper\Builder\ApiHelperBuilder;
use Ivory\GoogleMap\Helper\Builder\MapHelperBuilder;
use Ivory\GoogleMap\Map;
$map = new Map();
$mapHelper = MapHelperBuilder::create()->build();
$apiHelper = ApiHelperBuilder::create()
->setKey('API_KEY')
->build();
echo $mapHelper->render($map);
echo $apiHelper->render([$map]);
Good luck!
I'm getting an issue when I try to load this code, and I can't figure why it doesn't work...
<script type="text/javascript">
$(document).ready(function()
{
var geocoder = new google.maps.Geocoder();
$(".textarea-autosize").autosize();
geocoder.geocode({
address: '{$order->address_delivery["address1"]},{$order->address_delivery["postecode"]},{$order->address_delivery["city"]}'
}, function(results, status) {
if (status === google.maps.GeocoderStatus.OK)
{
var delivery_map = new google.maps.Map(document.getElementById('map-canvas'), {
zoom: 10,
mapTypeId: google.maps.MapTypeId.ROADMAP,
center: results[0].geometry.location
});
var delivery_marker = new google.maps.Marker({
map: delivery_map,
position: results[0].geometry.location,
url: 'http://maps.google.com?q={$order->address_delivery["address1"]},{$order->address_delivery["postcode"]},{$order->address_delivery["city"]}'
});
google.maps.event.addListener(delivery_marker, 'click', function() {
window.open(delivery_marker.url);
});
}
});
});
// Fix wrong maps center when map is hidden
$('#tabAddresses').click(function(){
x = delivery_map.getZoom();
c = delivery_map.getCenter();
google.maps.event.trigger(delivery_map, 'resize');
delivery_map.setZoom(x);
delivery_map.setCenter(c);
});
</script>
The error occurrs on the var geocoder = new google.maps.Geocoder();
Then I tried to load the following script : <script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?sensor=false"></script>
and I get another error :
'Uncaught TypeError: Cannot read property 'offsetWidth' of null'
Does anyone has any idea of why it doesn't work ?
Google maps aren't loaded at the time when you're trying to call it. You should be using this:
HTML:
<script src="https://maps.googleapis.com/maps/api/js?sensor=false&callback=initMap" async defer></script>
JS:
function initMap() {
// Google maps are now initialized.
}
You need to include the async and defer attributes into your script - this will make sure that the rest of the website keep loading instead of waiting for the script to load (which is handy, because it's quite big).
Secondly, you pass the "callback" parameter when calling the script. This is the name of the function that should be executed when the script is loaded. This way you can make sure you only initialize the map when it's actually loaded and present within your window.
Simply add this script to your html file:
<script async defer
src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&callback=initMap">
</script>
If you want to test the google geocoding api or check out some code, check out this link. Google Geocoding Service API Source
GD All,
I've been experimenting with google maps over last few days and was tring to get some interaction with the map by using a button to either drop a marker or draw a path.
From scouting around here and reading several posts I can find numerous options though all tell more or less same story, it should be relatively simple...
Unfortunately I have been unable to produce the desired result so far..:-(
I've tried several things:
- adding alerts, so I can see if the function is actually called = ok!
- integrating the code from the function in the initialize(), to check if the function code is ok = ok!
Yet still cannot seem to get it working...
So, the buttons do call the functions, yet they do not seem to update the map after the function call. I.e. there is nothing changing on the map...?
Any help will be much appreciated.
Basically they 'click listener in the initialize does the same as the 'callMe' function
Yet if I have the listener refer to the 'callMe' function it does not execute, eventhough the alert box triggers, a.k.a. the function is properly called.
My .php code:
<!DOCTYPE html>
<html>
<head>
<title>Simple click event</title>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<link href="/maps/documentation/javascript/examples/default.css" rel="stylesheet">
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>
<script>
function initialize() {
var mapOptions = {
zoom: 4,
center: new google.maps.LatLng(-25.363882, 131.044922),
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById('map-canvas'),
mapOptions);
var marker = new google.maps.Marker({
position: map.getCenter(),
map: map,
title: 'Click to zoom'
});
google.maps.event.addListener(map, 'center_changed', function() {
// 3 seconds after the center of the map has changed, pan back to the
// marker.
window.setTimeout(function() {
map.panTo(marker.getPosition());
}, 3000);
});
google.maps.event.addListener(marker, 'click', function() {
map.setZoom(8);
map.setCenter(marker.getPosition());
});
}
function callMe(){
alert('function called');
map.setZoom(8);
map.setCenter(marker.getPosition());
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>
<body>
<div id="map-canvas" style="width: 100%; height: 300px"></div>
<div>
<button id="btnOK" onclick="callMe()">Drop marker</button>
</div>
</body>
</html>
Many thanks !
Martijn
Your map variable is defined within the scope of the initialize function and is therefore not reachable inside callMe. You'll need to move the the definition outside initialize, or add a DOM listener inside that function to handle the button click.
I was wondering if anyone has any ideas/tutorials on how to plot various points on a google map, and save the points in a database with custom marker titles.
I want something similar to http://www.mapmyrun.com/create_new , where i can actually draw on a map and mark out paths and such.
Plotting the points is done in Javascript, I managed to learn everything I needed from the maps API docs:
http://code.google.com/apis/maps/documentation/javascript/basics.html
I scraped the code below off a site I made which moves a single point to where the mouse is clicked. You should be able to store a set of points in a JS array, or better, get them from the map when submitting your form then update a hidden form field with the values which can be inserted in your database with a php/python script on the server.
<html>
<head>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
</head>
<body onload="initialize()">
<div id="map_canvas" style="width:400px; height:600px; display:block; float:left">
</div>
</body>
</html>
<script type="text/javascript">
var map;
var marker = null;
function initialize() {
var myLatlng = new google.maps.LatLng(54, -2.0);
var myOptions = {
zoom: 6,
center: myLatlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
google.maps.event.addListener(map, 'click', function(event) {
placeMarker(event.latLng);
});
}
function placeMarker(location) {
var clickedLocation = new google.maps.LatLng(location);
if(marker == null){
marker = new google.maps.Marker({
position: location,
map: map
});
}else{
marker.setPosition(location);
}
map.setCenter(location);
}
</script>
Edit:
Here is a demo from docs site, which creates a list of points and draws a lines between them:
http://code.google.com/apis/maps/documentation/javascript/examples/polyline-simple.html
There are other examples there too. Just load them and press ctrl+u in firefox to view the source.