I basically want to have a script on the page which shows a map when it finds two fields on the page named "lng" and "lat" which have a value.
This means that if there are the fields on the page with values, then it will try and display a map, but if not, then it will not.
This is the code I have so far: http://jsfiddle.net/spadez/xJhmk/3/
function mapDisplay() {
var latval = $('input[id=lat]').val();
var lngval = $('input[id=lng]').val();
var mapOptions = {
zoom: 8,
center: new google.maps.LatLng(latval, lngval),
mapTypeId: google.maps.MapTypeId.ROADMAP,
disableDefaultUI: true,
scrollwheel: false,
draggable: false
};
var map = new google.maps.Map(document.getElementById('map_canvas'), mapOptions);
}
$(function () {
mapDisplay();
});
I am not very good at jquery at the moment but this is what I tried which didn't work:
if (latval !=NULL && lngval != NULL)){
...my code
}
Can someone with a little more knowledge help me understand why this approach doesn't work please?