The default weather API for Google Maps API v3 is nice, but I need an actual radar loop. I found an example of layering a KML file onto an existing map:
<script language=JavaScript type=text/JavaScript>
function loadGoogleMap_FacilityPage()
{
var myLatlng = new google.maps.LatLng(34.921467, -84.107919);
var mapOptions = {
zoom: 8,
center: myLatlng,
mapTypeId: google.maps.MapTypeId.ROADMAP,
}
var map = new google.maps.Map(document.getElementById("google_map"), mapOptions);
var ctaLayer = new google.maps.KmlLayer('http://mysite.com/southeastradar.kml');
ctaLayer.setMap(map);
}
</script>
But the radar is not being layered. The referenced kml file is located on valid server, and was retrieved from National Weather Service
Help with getting the KmlLayer working is appreciated.
Related
Im building a web app in order to show a marker in the users current location using geolocation and GPS. Here is my code
var marker;
$(window).load(function() {
myOptions = { zoom: 20, mapTypeId: google.maps.MapTypeId.ROADMAP };
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
var watchId = navigator.geolocation.watchPosition(centerMap);
});
function centerMap(location)
{
var myLatlng = new google.maps.LatLng(location.coords.latitude,location.coords.longitude);
map.setCenter(myLatlng);
map.setZoom(15);
$("#lat").text("Latitude : " + location.coords.latitude);
$("#lon").text("Longitude : " + location.coords.longitude);
//show current location on map
marker = new google.maps.Marker({
position: myLatlng,
map: map,
zIndex:1
});
navigator.geolocation.clearWatch(watchId);
}
This code works but it keep adding markers as the user changes location.
How i can show only one marker in the current users location?
Instead of generating a new marker each time centerMap is called simply update its position with marker.setPosition(myLatlng).
I'm trying to get my hands dirty on Google Maps API v3. But now I'm stuck with figuring out how to get the coordinates of a certain marker?
<script>
var homeLatlng = new google.maps.LatLng(16.61096000671, 120.31346130371);
var homeMarker = new google.maps.Marker({
position: homeLatlng,
map: map
});
var myOptions = {
center: new google.maps.LatLng(16.61096000671, 120.31346130371),
zoom: 10,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map =
new google.maps.Map(document.getElementById("map_canvas"), myOptions);
//I know that I'm the one who set the coordinates for this,
// but how do I fetch it back?
$('#plot').click(function(){
homeMarker.setMap(map);
});
</script>
homeMarker.getPosition(); //returns a google.maps.LatLng object
I'm looking for a method to my Google map auto refresh for each "n" seconds, now i'm refreshing all page, but i must to refresh only the map,
follow my JS code:
var DEFAULT_ZOOM = 14;
function initialize() {
var map;
var latlng = new google.maps.LatLng(-19.0, -59.0);
var myOptions = {
zoom: parseInt(getCookie("zoom_gm")),
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
initMarkers(map);
var zm = DEFAULT_ZOOM;
google.maps.event.addListener(map, 'zoom_changed',
function(){
zm = map.getZoom();
setCookie("zoom_gm", zm);
}
);
}
You will have to retrieve the new data using AJAX. Once you received the data, you have to walk the array/object you've received and add the new Markers. Depending on what you receive(maybe the response contains coordinates you've already set) you need to remove existing markers by using markerObj.setMap(null) .
That's all I can suggest so far, you're very stingy with informations.
I'm trying to do this.When a user comes to sites,i need to show him on google map and also will pass some latitude and longitude.Now my map has to show the path of user and the lat and long which i pass.
Using my below code,i pass my lat and long.Now,i need to show the user position.
How to show both this?
function initialize() {
var myOptions = {
zoom: 17,
center: new google.maps.LatLng(23.333,34.534),
mapTypeId: google.maps.MapTypeId.ROADMAP
}
var map = new google.maps.Map(document.getElementById("map_canvas"),
myOptions);
var image = 'image.png';
var myLatLng = new google.maps.LatLng(23.333,34.534);
var beachMarker = new google.maps.Marker({
position: myLatLng,
map: map,
icon: image
});
}
[This is how i tried]:http://dpaste.com/695949/
it did not work.
If you want to use HTML5 geo location then in your initialize function after you add the beachMarker put:
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(e) {
var marker = new google.maps.Marker({
map: map,
position: new google.maps.LatLng(e.coords.latitude, e.coords.longitude);
});
}, function() {
// Handle error here
});
}
To display directions on google map you need to have source and destination latlong. in your above code you have destination latlong but user latlong are missing. you need to first get user latlong then you have to use google direction renderer. for more reference read http://code.google.com/apis/maps/documentation/javascript/directions.html
user(source) latlong can be found in many ways -
using geocoder gem based on ip, address, etc.
using html5 geolocation read http://mobile.tutsplus.com/tutorials/mobile-web-apps/html5-geolocation/
I have a question relevant to Google Maps API. I am learning how to use the Google Maps API. I can just show the map in the div tag, but what I want is to be able to click on the map and show the marker and return the LatLng of the clicked point.
function initialize(v_lat,v_long,v_place) {
var latlng = new google.maps.LatLng(-34.397, 150.644);
var myOptions = {
zoom: 15,
center: latlng,
mapTypeId: google.maps.MapTypeId.SATELLITE
};
var map = new google.maps.Map( document.getElementById("map_canvas") , myOptions );
}
here is the click event example
where you click on map marker place on that point and click on marker which will return the latlng of that location.
try this
var marker;
google.maps.event.addListener(map, 'click', function() {
if(marker==null){
marker = new google.maps.Marker({
position: myLatlng,
map: map,
title:"Hello World!"
});
google.maps.event.addListener(marker, 'click', function() {
alert("latlng" + marker.getPosition());
});
}
});
here is the link for google map v3 you can find all tutorials related to the map
http://code.google.com/apis/maps/documentation/javascript/tutorial.html
http://code.google.com/apis/maps/documentation/javascript/events.html