ReferenceError: google is not defined - angular-google-maps

I want to embed google maps in to my project ,but got stuck with this issue ,i was searching for many solutions but none solved my issue. I really cant understand why this error is coming !
This is my javascript file
var mapOptions = {
zoom: 4,
center: new google.maps.LatLng(25,80),
mapTypeId: google.maps.MapTypeId.TERRAIN
}
$scope.map = new google.maps.Map(document.getElementById('map'), mapOptions);
$scope.markers = [];
var infoWindow = new google.maps.InfoWindow();
var createMarker = function (info){
var marker = new google.maps.Marker({
map: $scope.map,
position: new google.maps.LatLng(info.lat, info.long),
title: info.city
});
marker.content = '<div class="infoWindowContent">' + info.desc + '</div>';
google.maps.event.addListener(marker, 'click', function(){
infoWindow.setContent('<h2>' + marker.title + '</h2>' + marker.content);
infoWindow.open($scope.map, marker);
});
$scope.markers.push(marker);
}
for (i = 0; i < cities.length; i++){
createMarker(cities[i]);
}
$scope.openInfoWindow = function(e, selectedMarker){
e.preventDefault();
google.maps.event.trigger(selectedMarker, 'click');
}

Afaik, you are using angular and plain google sdk, which is pain (you have to use $apply everywhere, you must destroy events yourself, etc.), you should definitely checkout angular-google-maps module, it has great documentation, below working simple demo
angular.module('app', ['uiGmapgoogle-maps']).controller('ctrl', function($scope){
$scope.map = { center: { latitude: 45, longitude: -73 }, zoom: 8 };
});
.angular-google-map-container { height: 400px; }
<script src='http://maps.googleapis.com/maps/api/js'></script>
<script src="
http://cdnjs.cloudflare.com/ajax/libs/lodash.js/3.10.1/lodash.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.js"></script>
<script src="https://rawgit.com/angular-ui/angular-google-maps/master/dist/angular-google-maps.js"></script>
<script src="http://rawgit.com/nmccready/angular-simple-logger/master/dist/angular-simple-logger.js"></script>
<div ng-app="app" ng-controller="ctrl">
<ui-gmap-google-map center='map.center' zoom='map.zoom'></ui-gmap-google-map>
</div>

Related

GetFeatureInfo request to Geoserver returns an error,

I am trying to make a GetFeatureInfo request with WMS on Open Layers to Geoserver. The request appears to be made and loads on every click as expected but the "image" crashes every time. The request is made through a Proxy on my own computer which appears to be working well. Here is an image of the events and the code I have been using. As i am quite inexperienced with all components of this any help would be appreciated. Thank you guys.
The script :
<script>
var layers = [];
layers[0] = new ol.layer.Tile({
source: new ol.source.TileWMS({
url: 'http://localhost:8080/geoserver/AL2/wms?',
params: { LAYERS: 'AL2:A2', 'TILED': true, projection: 'EPSG:4326', VERSION: '1.1.1' },
servertype: 'geoserver'
})
});
layers[1] = new ol.layer.Tile({
source: new ol.source.OSM()
});
layers[2] = new ol.layer.Tile({
source: new ol.source.OSM()
});
var map = new ol.Map({
target: 'map',
layers: layers,
view: new ol.View({
center: ol.proj.fromLonLat([13, 56]),
zoom: 8,
EPSG: 4326,
})
});
function switchLayer(evt) {
layers[evt.value].setVisible(evt.checked);
}
map.on('singleclick', function (event) {
var url = '../../proxy/proxy.aspx?url=' + layers[0].getSource().getFeatureInfoUrl
(event.coordinate,
map.getView().getResolution(), map.getView().getProjection().getCode(),
{
INFO_FORMAT: 'text/html',
Layers: "AL2:A2"
});
if (url) {
document.getElementById('info').innerHTML =
'<iframe seamless src="' + url + '"></iframe>'
}
});
</script>
HTML:
<!DOCTYPE html >
<meta charset = "utf-8"/>
<title > OpenLayers </title>
<link rel = "stylesheet" href = "https://openlayers.org/en/v6.5.0/css/ol.css" type = "text/css">
<script src = "https://openlayers.org/en/v6.5.0/build/ol.js" script type = "text/javascript" ></script>
</head>
<body>
Geoserver
LTU
GPS

paper js display stop issue

I use paper.js and canvas to make web api, but when open web page , there is nothing until I move mouse on canvas. I don't know why.
code as follow, actually when I try to draw a box , it also like that.
<script language="javascript" type="text/javascript" canvas="canvas">
paper.install(window);
window.onload=function(){
var scope2 = new PaperScope();
paper = scope2.setup('controlpanel');
// var L_controlpanel = new Layer();
var bgshadoW = new Shape.Rectangle({
point:[10,10],
size:[200,360],
fillColor:'#f2f2f2',
shadowColor:'black',
shadowBlur: 12,
shadowOffset: [5, 5]
});
var colorfunC ;
var G_colorfunC = new Group();
var colorcontenT = ['#ffff66','#77ff33','#66b3ff','#f0aad9','#ffd486']
for (var i, i=0;i<5;i++){
colorfunC = new Path.Rectangle({
point:[20,20+30*i],
size:[15,15],
radius:5,
strokeColor: 'black',
strokeWidth: 1,
fillColor:'#f2f2f2',
data:{'click':0,'color':colorcontenT[i]}
});
G_colorfunC.addChild(colorfunC);
colorfunC.onClick = function(event){
G_colorfunC.fillColor='#f2f2f2';
this.fillColor=' #4dc3ff';
fillcolorshoT = this.data['color'];
}
fixdemO = new Path.Rectangle({
point:[60,20+30*i],
size:[50,15],
fillColor:colorcontenT[i]
});
}
var G_denVfunC = new Group();
var denVcontenT = [120,150,200,250,300]
for (var i, i=0;i<5;i++){
denVfunC = new Path.Rectangle({
point:[20,200+30*i],
size:[15,15],
radius:5,
strokeColor: 'black',
strokeWidth: 1,
fillColor:'#f2f2f2',
data:{'click':0,'denV':denVcontenT[i]}
});
G_denVfunC.addChild(denVfunC);
denVfunC.onClick = function(event){
G_denVfunC.fillColor='#f2f2f2';
this.fillColor='#4dffa6';
denV = this.data['denV'];
}
FixText = new PointText({
point:[60,212+30*i],
fontSize:14,
fillColor: 'black',
content:'DOMA density: '+denVcontenT[i]
});
}
}
</script>
found cause,just add
paper.view.update();

load google map geocoded in ajax page

I have a webapp where I load all my pages with ajax and now I´m trying to load a google map with the page below.
Problem solved, now I can load a google map with just an address(geocoded) with the below code.
<div id="map_external" class="notransform mapExternal">
<input id="address" type="hidden" value="kungsgatan 14,varberg,sweden">
<div id="header" class="toolbar">
<h1>Google Map</h1>
BACK
</div>
<div id="map_canvas" style=" height:600px!important;" class="notransform"></div>
<script>
jQuery(document).ready(function(){
$('#map_external').bind('pageAnimationStart', function(event, info){
if (info.direction == 'in') {
googleMaploadScript();
}
});
});
function googleMaploadScript() {
var script =document.createElement("script");
script.type="text/javascript";
script.src="http://maps.google.com/maps/api/js?sensor=false&callback=initialize";
document.body.appendChild(script);
//alert("script loaded");
}
var geocoder;
var map;
function initialize() {
geocoder = new google.maps.Geocoder();
var mapOptions = {
zoom: 15,
center: undefined,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
map = new google.maps.Map(document.getElementById('map_canvas'), mapOptions);
image = new google.maps.MarkerImage("http://www.mypage.com/images/googlemap/info.png",new google.maps.Size(32, 45));
shadowi = new google.maps.MarkerImage("http://www.mypage.com/images/googlemap/shadow.png",new google.maps.Size(51, 37));
codeAddress();
}
function codeAddress() {
var address = document.getElementById('address').value;
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
var marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location,
shadow: shadowi,
icon: image
});
} else {
alert('Geocode was not successful for the following reason: ' + status);
}
});
}
</script>
</div>
Problem solved, see the above on how to load a geocoded google map in an ajax loaded page.

Google Map V3: Loading Markers using AJAX+ASP/PHP and Reload on Ruquest or Event

Hi I've searched so many things and found many contents but didn't found what I required actually.
I can loading all markers but unable to Refresh it or Reload it please help me out here's the code:
$(document).ready(function() {
var myLatLng = new google.maps.LatLng(24.86802, 67.06416);
MYMAP.init('#map', myLatLng, 11);
$(document).ready(function(e){
MYMAP.placeMarkers('testasp.asp');
});
});
var curr_infw;
var MYMAP = {
map: null,
bounds: null,
infowindow:null
}
MYMAP.init = function(selector, latLng, zoom) {
var myOptions = {
zoom:zoom,
center: latLng,
mapTypeId: google.maps.MapTypeId.HYBRID
}
this.map = new google.maps.Map($(selector)[0], myOptions);
this.bounds = new google.maps.LatLngBounds();
}
MYMAP.placeMarkers = function(filename) {
$.get(filename, function(xml){
$(xml).find("marker").each(function(){
var name = $(this).find('name').text();
var address = $(this).find('address').text();
// create a new LatLng point for the marker
var lat = $(this).find('lat').text();
var lng = $(this).find('lng').text();
var point = new google.maps.LatLng(parseFloat(lat),parseFloat(lng));
var infowindow = null;
// extend the bounds to include the new point
MYMAP.bounds.extend(point);
var marker = new google.maps.Marker({
position: point,
map: MYMAP.map,
clickable: true,
icon: 'truck_green.png'
});
//var infowindow = null;
infoWindow = new google.maps.InfoWindow();
var html='<strong>'+name+'</strong.><br />'+address;
google.maps.event.addListener(marker, 'mouseover', function() {
infoWindow.setContent(html);
infoWindow.open(MYMAP.map, marker);
});
MYMAP.map.fitBounds(MYMAP.bounds);
});
});
}
If somebody help me out I want to refresh it using click event or settimeout function though.
Regards and looking forward to hear it here soon. thanks
Not an answer, but what's this meant to be?
$(document).ready(function() {
var myLatLng = new google.maps.LatLng(24.86802, 67.06416);
MYMAP.init('#map', myLatLng, 11);
$(document).ready(function(e){
MYMAP.placeMarkers('testasp.asp');
});
});
Why are you nesting document.ready? Just do
$(document).ready(function() {
var myLatLng = new google.maps.LatLng(24.86802, 67.06416);
MYMAP.init('#map', myLatLng, 11);
MYMAP.placeMarkers('testasp.asp');
});
For event use
google.maps.event.addListener([ mapObject ], 'bounds_changed', function() {
// [ update code here ]
});

Using sidebar click to trigger google maps event v3

Still stuck with this one can someone please help made some progress just having issues with the info windows now.
<div id="map"></div>
<div id="sidebar">
<h2>Sidebar</h2>
</div>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true"></script>
<script type="text/javascript">
var locations = [
['Bondi Beach', -33.890542, 151.274856, 4],
['Coogee Beach', -33.923036, 151.259052, 5],
['Cronulla Beach', -34.028249, 151.157507, 3],
['Manly Beach', -33.80010128657071, 151.28747820854187, 2],
['Maroubra Beach', -33.950198, 151.259302, 1]
];
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 10,
center: new google.maps.LatLng(-33.890542, 151.274856),
mapTypeId: google.maps.MapTypeId.ROADMAP
});
var infowindow = new google.maps.InfoWindow();
//console.log(infowindow);
var markers = [];
var marker = [];
var html = "<ul>";
for (i = 0; i < locations.length; i++) {
//console.info(marker.position());
marker = new google.maps.Marker({
position: new google.maps.LatLng(locations[i][1], locations[i][2]),
map: map,
icon: "http://lindsay-and-dan.gettingmarried.co.uk/images/maps/icon-music.gif"
});
//console.log(marker);
var center = marker.position;
markers.push(marker);
console.log(markers[i]);
google.maps.event.addListener(marker, 'click', (function(marker, i) {
return function() {
infowindow.setContent(locations[i][0]);
infowindow.open(map, marker);
//console.log(marker.position);
map.panTo(center);
}
})(marker, i));
//console.log(marker);
//console.log(locations[i][0]);
html += '<li>' + locations[i][0] + '</li>';
}
html += "</ul>";
$('#sidebar').html(html).fadeIn('slow');
$('.move').click(function(){
//infowindow.close();
var contents = $(this).attr('map');
var array = contents.split(',');
var lon = array[0];
var lat = array[1];
var content = array[2];
console.log(content);
infowindow.open(map, marker);
infowindow.setContent(content);
map.panTo(new google.maps.LatLng(lon,lat));
return false;
});
</script>
Here is a link to the test example.
http://extwit.users35.interdns.co.uk/gmap/
any suggestions???
Ok, so helping you DEFINITELY helped me. Your marker should look something like this:
marker = new google.maps.Marker({
position: new google.maps.LatLng(locations[i][1], locations[i][2]),
Oa: locations[i][1],
Pa: locations[i][2],
map: map,
icon: "http://lindsay-and-dan.gettingmarried.co.uk/images/maps/icon-music.gif"
});
Oa and Pa were added.
Hope this helps
P.S: I just noticed your other issue with the info window itself. Add infowindow.open(map,marker); and also the positioning of the infowindow is off...not really sure about that one.
P.P.S.: Your $('.move') block of code needs to be within the markers loop; within this block, replace your marker reference with markers[i]. This should do it for you!

Resources