Printing API-Generated Google Maps from Internet Explorer - javascript

Having an odd problem printing an API-generated (V3) Google Map from Internet Explorer 7 & 8.
I generate my map with JavaScript similar to the following:
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
function initialize() {
var centroid = new google.maps.LatLng(35.9948166667, -83.9781791667);
var myOptions = {
disableDefaultUI: true,
zoom: 12,
mapTypeId: google.maps.MapTypeId.ROADMAP,
center: centroid
};
var map = new google.maps.Map(document.getElementById("map"), myOptions);
var marker0 = new google.maps.Marker({
position: new google.maps.LatLng(36.1102, -83.9208),
map: map
});
var marker1 = new google.maps.Marker({
position: new google.maps.LatLng(36.001, -83.8646),
map: map
});
}
</script>
Typically there are about 25-35 markers on any of my maps. These print just great from Safari, Firefox, and Chrome, on both OS X & Windows XP. But, as soon as I try to print from Internet Explorer 7 or 8, the maps go all crazy: they overflow their boundaries that I set in the print CSS and the markers disappear from the map, leaving just a blank spot on the map.
Anyone encountered this/know how to proceed?
TIA.

IIRC, you'll have to use the Google Static Maps API if you want printer friendly maps.
It should be pretty easy to build the Static Maps API URL request string from the LatLng or your markers. One caveat is that the URL is limited to 2048 characters including any character escapes, this will limit how many markers you can have on the map at one time.
[Edit] In the Javascript API, markers have the class 'gmnoprint', which disables them from showing up on the printed rendering. You can iterate through the markers and remove this class, which should allow them to be printed on the page. As far as I know, this will not work for the direction lines.

Related

Google Maps Javascript API not working on mobile site

I'm building a site for a customer who wants a map on their "About Us" page showing their locations. I have the map working and fully functional on the desktop site (www.al-van.org/jake/aboutUs.html) using the Google Maps Javascript API. Everything is going good but when I try to view the site on my android device, I just get an "Oops something went wrong see the error console for more technical information" which doesn't help me a whole lot. I can't seem to figure out what is going on and why it won't work on mobile. I need to use the Javascript API because the client wants 2 locations on the map and the embed api won't do that. Here is my JS, the HTML is a simple div with a bootstrap framework.
<script>
function initMap()
{
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 16,
center: {lat: 42.389795, lng: -86.258617},
styles: [
{elementType: 'geometry'},
{elementType: 'labels.text.stroke'},
{elementType: 'labels.text.fill'}
]
});
// array used to label markers.
var labels = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
// Add some markers to the map.
var markers = locations.map(function(location, i) {
return new google.maps.Marker({
position: location,
label: labels[i % labels.length]
});
});
// Add a marker clusterer to manage the markers.
var markerCluster = new MarkerClusterer(map, markers, {imagePath:
'googlemaps/m'});
}
var locations = [
{lat: 42.390337, lng: -86.259642},
{lat: 42.388635, lng: -86.257246}
]
</script>
<script src="googlemaps/markerclusterer.js"></script>
<script async defer src="https://maps.googleapis.com/maps/api/js?
key=API_KEY&callback=initMap"></script>
After working with Google Support, it seems that the issue is in the way that the android Chrome puts in the website. I had explicitly set my allowed HTTP referrers all including www.blahblahblah.com and various variations using wildcards. What I DID NOT DO was include a wildcard in place of the "www" When I placed my wildcard as blahblah.com it allowed it to work on the mobile phone. For some reason, unless you explicitly type "www.example.com" into your android Chrome browser, it will not auto-fill the "www." This is what solved my issue, I hope it helps in the future.
Your API key is invalid for the domain, or is over it's quota limit.
Go here: https://developers.google.com/maps/documentation/javascript/get-api-key
To get an API key for the domain you are using.

Google Maps Javascript API does not open blank grey

I'm trying to develop an asp.net project using Google Maps and JavaScript. For three days my map was opening perfectly. But today the map zoom and other map control buttons are coming but map doesn't come. Instead map grey blank is coming.
HereIsTheImage and here is my js code:
function LoadHarita() {
var myLatlng = new google.maps.LatLng(33.3, 33.3);
var myOptions = {
zoom: 16,
center: myLatlng,
disableDefaultUI: true,
panControl: true,
zoomControl: true,
zoomControlOptions: {
style: google.maps.ZoomControlStyle.DEFAULT
},
mapTypeControl: true,
mapTypeControlOptions: {
style: google.maps.MapTypeControlStyle.HORIZONTAL_BAR
},
streetViewControl: true,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
var map = new google.maps.Map(document.getElementById('map-canvas'), myOptions);
}
What's the problem? The map quota or limits? But what kind of limits for 3 days? I didn't understand it.
Thanks guys. Solved the problem. Here is the details if anyone needs it.
I opened the console by pressing F12. There was saying that i've added multiple maps.
I wrote the google map javascript codes under http://maps.google.com/maps/api/js to top of my javascript code. I deleted all these code on my js. And my map comes :) Normally i won't able to reach the map yesterday because i've added these codes yesterday. Maybe cookie is the reason. Whatever my map comes :) Thanks again
I had the same problem. Turned out it was Internet Explorer's 'Compatibility view' that was wrecking Google's Map code when running in localhost. Turning compatibility view off in IE11 made it work again.
The API call limit for Google Maps is 25000/day or something. It's very unlikely you managed to hit that just by playing around while developing. Try running your code in different browsers to see if it makes any difference.

Web maps api to see in 45 deg angle

I've been searching for a map API that allows me to see in a 45 degree angle, such as Google Earth does.
So far I haven't found any, and I know that Google Maps and Bing Maps do not have this function. And any others found do not include the country required: Portugal.
I'm searching for, preferably, a map that is not installed by a plugin, but in last case, I will work with that.
With google maps this is possible. You must use the tilt property in mapOptions
var mapOptions = {
center: new google.maps.LatLng(36.964645, -122.01523),
zoom: 18,
mapTypeId: google.maps.MapTypeId.SATELLITE,
tilt: 45
};
map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
}
Look at this sample from google dev

Get ExtendedData from KML with Google Maps API

I have a KML export from google maps, and some pointers have images or youtube videos. When i open the kml i see a tag on some pointers with youtube and image links. But when i load them into the Google Maps Api i cant see these urls.
This is what i have:
function initialize() {
var mapOptions = {
center: { lat: 52.448346, lng: 4.602585},
zoom: 12
};
var map = new google.maps.Map(document.getElementById('map-canvas'),mapOptions);
var kmlLayer = new google.maps.KmlLayer({
url: 'test_1.kml',
clickable: true,
preserveViewport: true,
map: map
});
google.maps.event.addListener(kmlLayer, 'click', function(event) {
console.debug(event);
});
}
google.maps.event.addDomListener(window, 'load', initialize);
Is there something to extract the media from the pointers?
My solution would be to export to a xml or json then build a map from it since ExtendedData of kml is partially supported by design, check out the documentation here
Here a possible duplicate of this question: Accessing ExtendedData information via Google Maps API v3

How to highlight a user's current location in google maps?

I am using following code to get the location of user in phonegap (it works fine)
function getLocation() {
var win = function(position) {
var lat = position.coords.latitude;
var long = position.coords.longitude;
var myLatlng = new google.maps.LatLng(lat, long);
var myOptions = {
center: myLatlng,
zoom: 7,
mapTypeId : google.maps.MapTypeId.ROADMAP
};
var map_element = document.getElementById("displayMap");
var map = new google.maps.Map(map_element, myOptions);
};
var fail = function(e) {
alert('Error: ' + e);
};
var watchID = navigator.geolocation.getCurrentPosition(win, fail);
}
This is working fine by centering the user's current location on the map. But I would like to show an indicator (a red dot) on the user's location. But I can see that google API provide only 3 options center, zoom and mapTypeId.
Are there any available options that can be used to highlight the position or is there a workaround?
EDIT
Was able to find that google maps API has a marker ho highlight any position. That looks helpful, but that shows a default red balloon, can that be modified by a custom image?
You can use the newly released GeolocationMarker which is part of the Google Maps API Utility Library.
It will add a marker and accuracy circle at the user's current location. It also allows a developer to customize the marker using the setMarkerOptions method and specifying an icon property.
Use icon inside marker like
var Marker = new google.maps.Marker({
map: map,
animation: google.maps.Animation.DROP,
position: "",
icon: /bluedot.png
});
you can use this google map location indication circular blue dot icon similar to the google map
You can use MarkerOptions to set a custom image. Check the Google Maps Javascript API V3 Reference to more details about Google Maps.

Categories