Google Maps marker not showing at all - asp.net

I developed many websites using the same google maps code, but this time my marker is not showing and I can't figure out why.
This is the code:
<link href="<%= Page.ResolveUrl("~/Assets/Styles/map.css") %>" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
function initializeMap() {
var latitude = 45.483995;
var longitude = 9.181769;
var latlng = new google.maps.LatLng(latitude, longitude);
var myOptions = {
zoom: 15,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
var image = '<%= Page.ResolveUrl("~/Assets/Images/Contacts/Baloon.png") %>';
var myLatLng = new google.maps.LatLng(45.4530, 9.2115);
var beachMarker = new google.maps.Marker({
position: myLatLng,
map: map,
icon: image
});
}
</script>
And this is map.css file:
#map_canvas
{
height: 300px;
width: 400px;
text-align: center;
}
Picture is correctly on server and I can open it via browser url..
Here is a link: LINK

I think the problem is simply that the coordinates you give for the marker are out of the map boundaries. You can see it if you zoom out a bit.
Here's an example using using the coordinates used to initialize the map as the marker's coordinates: http://jsfiddle.net/Dn7Rf/1/
Or rather one centering the map around the marker: http://jsfiddle.net/Dn7Rf/2/

Related

Cannot load KML file

Good Day,
Why I cannot load KML file made in My maps to my site ?
here is the code i'm using
map = new google.maps.Map(document.getElementById("mapa"), mapOptions),
json = JSON.parse($.trim($('#json .content').html())).nodes,
markers = [],
centerControlDiv = document.createElement('div'),
centerControl = new ControlesMapa(centerControlDiv, map);
var ctaLayer = new google.maps.KmlLayer({
url: 'http://www.santos.sp.gov.br/mapadeobras/sites/all/themes/mapadeobras/kml/bairros.kml',
map: map
});
when i tried with the file from example. It worked fine
var ctaLayer = new google.maps.KmlLayer({
url: 'http://googlemaps.github.io/js-v2-samples/ggeoxml/cta.kml',
map: map
});
I have tested the kml file on google validator and it's ok. The kml file is public as I've read here in another post.
Please Help
This works. Try specifying the center of the area of interest if it does not auto-jump to the region as defined in KML.
code snippet:
function initialize() {
var location = new google.maps.LatLng(-23.954785,-46.348161);
var mapOptions = {
zoom: 11,
center: location
}
var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
var ctaLayer = new google.maps.KmlLayer({
url: 'http://www.santos.sp.gov.br/mapadeobras/sites/all/themes/mapadeobras/kml/bairros.kml',
map: map
});
}
google.maps.event.addDomListener(window, 'load', initialize);
html,
body,
#map-canvas {
height: 100%;
width: 100%;
margin: 0px;
padding: 0px
}
<script src="https://maps.googleapis.com/maps/api/js"></script>
<div id="map-canvas"></div>

Implementing MarkerClusterer into Google Maps API - no markers showing

I have been trying to implement markerclusterer into my website for the past few weeks and everything I have tried has failed. I have no experience with code at all so everything I've been doing is trial and error.
The website I'm trying to add markerclusterer to is rfmaps.com.au.
I'm unsure as to what I'm doing wrong, and what needs to be fixed and really just need some good advice and help.
Here is the html code that I've been trying to get working. This code is simply all the bits and pieces I've been able to find from forums, all stuck together, and slightly edited (what I could figure out from help from forums)
<!DOCTYPE html>
<html>
<head>
<style>
html, body, #map-canvas {
margin: 0;
padding: 0;
height: 100%;
}
</style>
<script type="text/javascript"
src="http://maps.google.com/maps/api/js?sensor=false">
</script>
<script type="text/javascript">
var map;
var layerl0;
function initialize() {
map = new google.maps.Map(document.getElementById('map-canvas'), {
center: new google.maps.LatLng(-25, 133),
zoom: 5,
mapTypeId: google.maps.MapTypeId.HYBRID
});
for (var i = 0; i < 1000; ++i) {
var latLng = new google.maps.LatLng(data.photos[i].latitude,
data.photos[i].longitude)
var marker = new google.maps.Marker({
position: latLng,
draggable: true,
icon: markerImage
});
markers.push(marker);
}
var map = new google.maps.Map(document.getElementById("map"), options);
var mc = new MarkerClusterer(map);
layerl0 = new google.maps.FusionTablesLayer({
query: {
select: "'col2'",
from: '1UxncvVQSGcSvuN3t686sNuDQUsn8vQ6mws3zsvk'
},
map: map,
styleId: 4,
templateId: 1
});
}
function changeMapl0() {
var searchString = document.getElementById('search-string-l0').value.replace(/'/g, "\\'");
layerl0.setOptions({
query: {
select: "'col2'",
from: '1UxncvVQSGcSvuN3t686sNuDQUsn8vQ6mws3zsvk',
where: "'Location' CONTAINS IGNORING CASE '" + searchString + "'"
}
});
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>
<body>
<div id="map-canvas"></div>
<div style="margin-top: 10px;">
<label>Location</label><input type="text" id="search-string-l0">
<input type="button" onClick="changeMapl0()" value="Search">
</div>
</body>
</html>
I think you have not added the 'map' object while creating the markers inside the map.
This is your code:
var marker = new google.maps.Marker({
position: latLng,
draggable: true,
icon: markerImage
});
Please add map: map while generating your markers, like this:
var marker = new google.maps.Marker({
map: map,
position: latLng,
draggable: true,
icon: markerImage
});
Regarding marker cluster you need to add this js file- markerclusterer.js
markerCluster = new MarkerClusterer(map, marker);

how to close infowindow in google maps v3

I have tried to implement the last code at
https://developers.google.com/maps/articles/phpsqlinfo_v3
I want to have a cancel and close button.
So, i modified the code and uploaded it to
http://adsany.com/testclose.htm
(view source)
when i click on the map, a marker appears,
when I click on the marker, infowindow appears.
when I click on the cancel and close button, it closes the window, but a new marker appears.
So, i want to close the infowindow without creating a new marker.
Please suggest.
Thanks.
I hope this link will solve your Problem :-
http://gmaps-samples-v3.googlecode.com/svn/trunk/single-infowindow/single-infowindow.html.
<html>
<head>
<title>Single Info Windows</title>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
google.maps.event.addDomListener(window, 'load', function() {
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 13,
center: new google.maps.LatLng(37.789879, -122.390442),
mapTypeId: google.maps.MapTypeId.ROADMAP
});
var infoWindow = new google.maps.InfoWindow;
var onMarkerClick = function() {
var marker = this;
var latLng = marker.getPosition();
infoWindow.setContent('<h3>Marker position is:</h3>' +
latLng.lat() + ', ' + latLng.lng());
infoWindow.open(map, marker);
};
google.maps.event.addListener(map, 'click', function() {
infoWindow.close();
});
var marker1 = new google.maps.Marker({
map: map,
position: new google.maps.LatLng(37.789879, -122.390442)
});
var marker2 = new google.maps.Marker({
map: map,
position: new google.maps.LatLng(37.787814,-122.40764)
});
var marker3 = new google.maps.Marker({
map: map,
position: new google.maps.LatLng(37.767568,-122.391665)
});
google.maps.event.addListener(marker1, 'click', onMarkerClick);
google.maps.event.addListener(marker2, 'click', onMarkerClick);
google.maps.event.addListener(marker3, 'click', onMarkerClick);
});
</script>
<style type="text/css">
body {
font-family: sans-serif;
}
#map {
width: 500px;
height: 500px;
}
</style>
</head>
<body>
<h2>Demonstrates how to share a single info window on a map.</h2>
<ol>
<li>Click a marker to open a single info window containing the marker's position.</li>
<li>Close the opened info window by clicking anywhere on the map.</li>
</ol>
<div id="map"></div>
</body>
</html>

marking a location on the map v3

I am using the simple code to create a map on my site:
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>
var map;
function initialize() {
var mapOptions = {
zoom: 12,
scrollwheel: false,
center: new google.maps.LatLng(38.80962, -77.13143),
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById('map_canvas'),
mapOptions);
var customMarker = new google.maps.Marker({
position: latlng,
map: map,
shadow: shadow,
title:"Carlos Gallupa HQ",
icon: image
});
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
Now I am having issue pinpointing my location using a marker. Any idea how I can do it simple and right? Thanks.
It looks as if your marker position is not defined anywhere. Try this:
var customMarker = new google.maps.Marker({
// Here is the change:
position: map.getCenter(),
map: map,
shadow: shadow,
title:"Carlos Gallupa HQ",
icon: image
});

count markers displayed on map after zoom in and out

I am using google-maps-utility-library-v3.
I am trying to zoom in and zoom out, if the dot is not in screen anymore, I want to see count 0.
But it doesn't work. If I comment out mgr.addMarkers(markers,5); It works.... But it will always be 0 because no maker is managed by the manager.
Could someone tell me why?
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<style type="text/css">
html { height: 100% }
body { height: 100%; margin: 0; padding: 0 }
#map_canvas { height: 100% }
</style>
<script type="text/javascript"
src="http://maps.googleapis.com/maps/api/js?key=??????????????&sensor=false">
</script>
<script type="text/javascript" src="downloadxml.js"></script>
<script src="http://google-maps-utility-library-v3.googlecode.com/svn/tags/markermanager/1.0/src/markermanager.js"></script>
<script type="text/javascript">
var map = null;
function initialize() {
var myOptions = {
zoom: 8,
center: new google.maps.LatLng(42.35428, -71.05525),
mapTypeId: google.maps.MapTypeId.ROADMAP
}
map = new google.maps.Map(document.getElementById('map'), myOptions);
//hard code a marker
var lat = 42.35428;
var lng = -71.05525;
var point = new google.maps.LatLng(lat,lng);
var html = "I am a hard-coded dot";
var marker = new google.maps.Marker({
map: map,
position: point,
icon: "http://www.google.com/mapfiles/arrow.png",
shadow: "http://www.google.com/mapfiles/arrowshadow.png"
});
var markers = [];
markers.push(marker);
var mgr = new MarkerManager(map);
mgr.addMarkers(markers,5);
mgr.refresh();
google.maps.event.addListener(map, 'zoom_changed', function() {
var zoomLevel = map.getZoom();
var count = mgr.getMarkerCount(zoomLevel);
document.getElementById("Listing").innerHTML += count + "<BR>";
});
}
</script>
You appear to be using the MarkerManager before it is fully initialized. Here's an updated section of your code to fix the issue:
var markers = [];
markers.push(marker);
var mgr = new MarkerManager(map);
google.maps.event.addListenerOnce(mgr, 'loaded', function(){
mgr.addMarkers(markers, 5);
mgr.refresh();
});
See this example as reference: http://google-maps-utility-library-v3.googlecode.com/svn/tags/markermanager/1.0/docs/examples.html

Resources