Overlay Marker Points with ids on google maps api - javascript

I have what I think is a tricky question, but hopefully someone on here can keep me from tearing my hair out!
I'm currently trying to figure out how to overlay a bunch of markers on a google map overlaid with a hosted tileJson layer.
I'm also trying to follow this tutorial so that I can load pictures and text into the sidebar when the user clicks on any of the map points:
http://www.dougv.com/2007/07/12/using-ajax-to-update-a-non-map-div-via-google-maps-apis-gdownload-and-gmarker-onclick-event/
The tutorial is designed for maps api2 (I'm using 3) although it looks like it could easily be updated for api 3.
Right now, in part because of the javascript connector that simplifies importing the custom tiles, I can't seem to get markers to work, let alone connect them to databases, and access them from outside the map window.
https://mywebspace.wisc.edu/axler/Web%20Deep%20Map/Web%20Map%20Google%20Maps/index2.html
Live map tiles... at the above link. No points are working yet but I put some sample points in a list in the code.
Any suggestions? Here is my code.
<html>
<head>
<title>GOOGLE MAPS TILEMILL</title>
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?key=AIzaSyD6VG2UbuMLDCQoZ-GOPZl_PU7r1jXzejU&sensor=false">
</script>
<script
src='wax/dist/wax.g.min.js'
type='text/javascript'></script>
<link href='wax/theme/controls.css' rel='stylesheet' type='text/css' />
<link href='style.css' rel = 'stylesheet' type ='text/css' />
<link href='controls.css' rel = 'stylesheet' type = 'text/css' /><script>
var map;
var sidebar;
function pageLoad() {
sidebar = document.getElementById('sidebar');
addPoint(1, 'Howards Fish House', 46.72.30616121527788, -92.15);
addPoint(2, 'Rices Point', 46.78, -92.18);
addPoint(3, 'Wild Rice Seeding Area', 46.80, -92.22);
wax.tilejson('http://a.tiles.mapbox.com/v3/slre.st-louis-river-estuary.jsonp',
function(tilejson) {
var map = new google.maps.Map(
document.getElementById('mymap'), {
center: new google.maps.LatLng(46.72, -92.15),
disableDefaultUI: false,
zoom: 12,
panControl: false,
zoomControl: true,
zoomControlOptions: {
position: google.maps.ControlPosition.TOP_RIGHT
},
scaleControl: true,
streetViewControl: false,
mapTypeControl: false,
mapTypeId: google.maps.MapTypeId.ROADMAP });
// Use this code to set a new layer as a baselayer -
// which means that it'll be on the bottom of any other
// layers and you won't see Google tiles
map.mapTypes.set('mb', new wax.g.connector(tilejson));
map.setMapTypeId('mb');
//I want to place a number of points on top of the MapBox hosted tile layer that is specified by wax.tilejson
});
}
function addPoint(pid, name, lat, lng) {
var point = new google.maps.LatLng(lat, lng);
var marker = new google.maps.Marker(point);
map.setMap(marker);
var info = '<strong>' + name + '</strong><br />';
info += 'For more information, click the icon.';
google.maps.event.addListener(marker, 'mouseover', function() {
marker.openInfoWindow(info);
});
google.maps.event.addListener(marker, 'mouseout', function() {
map.closeInfoWindow();
});
google.maps.event.addListener(marker, 'click', function() {
details.innerHTML = '<em>Loading information ...</em>';
showDivInfo(pid);
});
}
</script>
</head>
<body onload="pageLoad()" onunload="pageUnload()">
<div id='sidebar'>
<h2>Explore the St. Louis River Estuary</h2>
<p>Click on the map points to learn about the stories and science that define the region!</p>
<p><span class='source'>Source: <a href='http://www.stlre.pebbleonline.com'>Main Web Page</a></span></p>
</div>
<div id='mymap'></div>
</body>
</html>

This map.setMap(marker); looks wrong.
should be
marker.setMap(map);
:)

Related

How do I make markers draggable, labeled, and deletable? with Google maps javascript API

First of all, I know Google has documentation on how to complete all of these features, but even when I add the exact coding, the map no longer shows up, or it simply does not work.
I'm completely new to development, but the project I'm trying to complete is a Game of Thrones map, where other users may visit and add a marker, name the marker ( not a simple one-character label, more like an actual name, several characters long ), and delete their marker. If someone else adds a marker, I'd like to be able to see it. And vice versa, I want everyone's markers on the map to be visible.
So far, as a first step, all I'm trying to complete right now is creating markers and making them draggable. The map shows up fine, until I add the value "draggable:true" to the markers options. even though that's what the google documentation suggests.
Here's the google documentation: https://developers.google.com/maps/documentation/javascript/markers
And here's the page i'm trying to get the project to work on:http://jamie-jabbours-fabulous-project.webflow.io/
and here's the exact code i'm using:
<!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
draggable: true
});
}
</script>
<script async defer
src="https://maps.googleapis.com/maps/api/js?key=AIzaSyB55_iwgWvg1_NjoIEqqXgeQOeDBrq8p5o&callback=initMap">
</script>
</body>
</html>
I'm sure there is something very simple I'm doing wrong, but I can't see it.
Just add a comma..after map and before draggable
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,
draggable: true
});
}
Watch out for syntax bugs next time :)

Google maps zoom scrollbar does not appear on new version

I have a web-page here. It uses google maps and it worked well. Recently a new version of google maps was released where some changes were made. For instance, instead of e.latLng.F, e.latLng.lng and instead of e.latLng.A, e.latLng.lat should be used. So far, so good. However, for some reason, the zoom scrollbar cannot be seen. I know one can still zoom with mouse scrolling, however, what about devices where mouse scroll is not defined, like a laptop with a touchpad?
This is a part of initialization:
var mapOptions = {
center: { lat: lat, lng: lon},
zoom: 14
};
if (!administrator) {
mapOptions.mapTypeId = google.maps.MapTypeId.HYBRID;
}
var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
I believe I should define an attribute for mapOptions, but I do not know what should be defined there. When I searched for this on google, I have not found the answer. It is possible that I will find out the answer soon, but anyway, I ask the question here to make sure that others will have an answer to this question in the future. Thanks.
EDIT:
At this page I can see a zoom control. This is the code there:
<!DOCTYPE html>
<html>
<head>
<script
src="http://maps.googleapis.com/maps/api/js">
</script>
<script>
function initialize()
{
var mapProp = {
center: new google.maps.LatLng(51.508742,-0.120850),
zoom:7,
zoomControl:true,
zoomControlOptions: {
style:google.maps.ZoomControlStyle.SMALL
},
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("googleMap"),mapProp);
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>
<body>
<div id="googleMap" style="width:500px;height:380px;"></div>
</body>
</html>
if I modify it to this:
<!DOCTYPE html>
<html>
<head>
<script
src="http://maps.googleapis.com/maps/api/js">
</script>
<script>
function initialize()
{
var mapProp = {
center: { lat: 51.508742, lng: -0.120850},
zoom:7,
};
var map = new google.maps.Map(document.getElementById("googleMap"),mapProp);
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>
<body>
<div id="googleMap" style="width:500px;height:380px;"></div>
</body>
</html>
the zoom control is still displayed. I wonder why is the zoom control displayed at w3c and not at my end, since:
both the example and my code uses a div
the properties are initialized in a similar manner
the map is initialized in a similar manner
the dom listener is initialized in a similar manner
They've removed the scroll bar from the newest API, but they left the + and - zoom controls. Strangely, I see that your map doesn't have those either.
This article about the changes made to the map controls might be useful
The zoom control was always displayed, but the footer overflown it. It seems that the zoom control is positioned to the right bottom by default, while earlier it was positioned to the left top by default. The solution is either to make sure that the div where the map is displayed is displayed fully, or to initialize the position of the zoom control, like this:
var mapOptions = {
center: { lat: lat, lng: lon},
zoom: 14,
zoomControlOptions: {
position: google.maps.ControlPosition.LEFT_TOP
}
};

Connect dynamic data with google marker

I want to connect my dynamic data with google map marker here is my code
this is my mapdata and listdata both having same value which coming from the php
latitude: "19.1904917"
logitude: "72.8639419"
name: "Monkey d luffy"
using this latitude and logitude i m showing google marker on map for show marker data i used this code
var defaultLatlng = new google.maps.LatLng(19.0822508,72.8812041);
var myOptions = {
zoom: 10,
panControl:false,
streetViewControl:false,
center: defaultLatlng,
mapTypeId: google.maps.MapTypeId.ROADMAP,
zoomControl:true,
zoomControlOptions: {
style:google.maps.ZoomControlStyle.SMALL
},
};
loadMap();
function loadMap(){
console.log('loadMap');
// create new map make sure a DIV with id myMap exist on page
map = new google.maps.Map(document.getElementById("myMap"), myOptions);
geocoder = new google.maps.Geocoder();
//oms = new OverlappingMarkerSpiderfier(map,{markersWontMove: true, markersWontHide: true});
// create new info window for marker detail pop-up
$.each(mapdata.locations,function(key,val){
loadMarker(val);
});
$.each(listdata.locations,function(key,val){
loaddata(val);
});
}
this is my loadmarker function which showing marker on google maps
function loadMarker(markerData)
{
var myLatlng = new google.maps.LatLng(markerData['latitude'],markerData['logitude']);
console.log(myLatlng);
// create new marker
var marker = new google.maps.Marker({
map: map,
title: markerData['address'],
position: myLatlng
//animation:google.maps.Animation.BOUNCE
});
marker.setIcon('http://maps.google.com/mapfiles/ms/icons/red-dot.png');
gmarkers.push(marker);
var marker_num = gmarkers.length-1;
google.maps.event.addListener(marker, 'click', function() {
showMarker(markerData,marker);
});
}
this is my loaddata function which is showing my data on UI
function loaddata(markerData)
{
listitem += "<div class='expert_name'>"
+markerData['name']+
+"</div>"
$('#_mymaplist').html(listitem);
}
this is my html where i add all this thing
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Multiple Markers Google Maps</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<script src="https://maps.googleapis.com/maps/api/js?v=3.11&sensor=false" type="text/javascript"></script>
</head>
<body>
<div id="mymap" style="width: 800px; height:500px;"></div>
<div id="_mymaplist" style="width: 800px; height:500px;"></div>
</body>
</html>
i want when i hover name from _mymaplist div then google marker color has to change for the example here i only give one data but there will be more than one
i checked many example like this but i won't work for me
because this example having same function for loading the data..but in my case i have 2 function to load data. i also can use 1 function but problem is that map marker loading all data at one time and the list data is using pagination form loading data....so that y i can't use same function for loading data Please help me
Because of the issue of pagination if you have to use 2 functions, you can use the Styled Marker in the loaddata() function itself where you are defining your individual markers. For that you will need to use set(property, value) methods.
this.styleIcon.set('color', '00fff0');
This has to be defined inside your loaddata() function where your listitems are initialized.
function createStyle() { return new StyledIcon(StyledIconTypes.BUBBLE,{color:"#95AA7B",text:"click me!",fore:"#ffffff"}); }
listitem += "<div class='expert_name'>"
+markerData['name']+
+"</div>"
$('#_mymaplist').html(listitem);
google.maps.event.addDomListener(marker4,"click", function(o){
this.styleIcon.set("fore","#ffffff");//test color
this.styleIcon.set("color","#C2554D");// background color
this.styleIcon.set("text","color changed");
});
Hope this would Help!!

function javascript to set the position in google maps

Good afternoon,
I am developping a javaFX application and now I want to include on it a map using google maps
I have successfully dispaly the map on javaFX using this code on a html file
<!DOCTYPE html>
<html>
<head>
<title>Java-Buddy: Google Maps</title>
<script src="http://maps.google.com/maps/api/js?sensor=false"></script>
<style>#mapcanvas { height: 360px; width: 100%}</style>
</head>
<body>
<h1>Java-Buddy: Google Maps</h1>
<div id="mapcanvas">
<script type="text/javascript">
var latlng = new google.maps.LatLng(35.857908, 10.598997);
var Options = {
zoom: 15,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("mapcanvas"), Options);
//var carMarkerImage = new google.maps.MarkerImage('resources/images/car.png');
var marker = new google.maps.Marker({
position: new google.maps.LatLng(35.857908, 10.598997),
map: map,
draggable: false,
//icon: carMarkerImage,
title: "",
autoPan: true
});
</script>
</div>
</body>
</html>
I want to set the postition of the map using the controller class
I can do it with this event code
public void handle(ActionEvent actionEvent) {
webEngine.executeScript("document.myFunction(longitude, latitude)");}
I am new on javascript, and I want to know how to write the javascript function that allow me to set or to change the current position on the map
Thank you
function myFunction(longitude, latitude){
map.setCenter(new google.maps.LatLng(latitude, longitude));
}

google maps api 3 - show specific continent only

Please assist. Ive googled and gone through stack overflow but am unable to find this information anywhere. Is there a way to show only a specific continent, in my case Africa and hide all other unwanted continents in google maps. These maps shouldn't show at all. I came across this article -> Can i hide land masses with Google Maps API
But there is no specific example.
I am using Google Maps API 3.
Currently I have:
<script type="text/javascript"
src="https://maps.googleapis.com/maps/api/js?key=mykey&sensor=true">
</script>
<script type="text/javascript">
function initialize() {
//Implement map styling
var styles = [
{
"stylers": [
{"visibility": "simplified"}
]
}
];
var styledMap = new google.maps.StyledMapType(styles, {name: "MyMap"});
var mapOptions = {
center: new google.maps.LatLng(0.972198, 23.994141),
zoom: 3,
mapTypeId: google.maps.MapTypeId.ROADMAP,
panControl: false,
zoomControl: false,
streetViewControl: false,
mapTypeControl: false,
mapTypeIds: [google.maps.MapTypeId.ROADMAP, 'map_style'],
draggable: false,
scrollwheel: false,
panControl: false
};
var map = new google.maps.Map(document.getElementById("map-canvas"), mapOptions);
//Load kml of africa
var kmlMap = new google.maps.KmlLayer('http://myOverLay.kmz',
{
//suppressInfoWindows: false,
//map: map,
preserveViewport: true
});
kmlMap.setMap(map);
//map.mapTypes.set();
//Associate the styled map with the MapTypeId and set it to display.
map.mapTypes.set('map_style', styledMap);
map.setMapTypeId('map_style');
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
One option:
Cover the whole world except for a hole over your continent of choice. example of concept (US state of Virginia)
Limit the zoom and the bounds to prevent the map from going too far from showing that continent. description of how to limit the viewable area
Doesnt seem possible. Ended up using image mapster

Categories