I am creating a map object with a long/lat position as center. When clicking the google logo in the bottom left corner you are routed to google maps with the same position as center. But in the embedded map I have also added a marker at the center position.
Is it possible to have that marker set when you route to google maps as well?
I couldn't find anything in the documentation..
The logo's link looks like this:
https://maps.google.com/maps?ll=40.758893,-73.985132&z=10&t=m&hl=en-US&gl=US&mapclient=apiv3
In your case all you have to do is change the parameters of the link.
Using the ?q=40.758893,-73.985132 parameter instead of ?ll=40.758893,-73.985132 is probably enough for you. The q=latitude,longitude puts a marker to the position. Although it is possible to use both parameters. The q is the marker's position and the ll is the center of the map. (use the & separator between them).
I think it is against the Google Maps API ToS to modify the Google branding or the link. But anyway it is possible with javascript.
You can see the original answer here: How to change Google logo's href
After the map is loaded you can manipulate the link:
...
map.addListener('tilesloaded', function(){
modifyLogoLink();
});
...
And here is how to change the link:
function modifyLogoLink(){
var anchors = document.getElementsByTagName('a'),
l = anchors.length,
i,
a;
for (i = 0; i < l; i++) {
a = anchors[i];
if (a.href.indexOf('maps.google.com/maps?') !== -1) {
// here you can manipulate the anchor
a.href = a.href.replace('ll=', 'q=')
}
}
}
Please also note that the Google's link is changed every time when the map is dragged or zoomed. So you must handle this as well.
Hope this helps.
Related
I checked that there are checkresize() methods from google Map's native API.. but it doesn't seem to work with the refresh function from gmaps.js.
Does anyone has similar problems using AngularJS and gMaps.js? How do you come to solve it?
After i resize the window, the map appears again. So I am thinking is there anyway to check resize on initialization for gMap.js?
ng-cloak did not work for me when I tried it. I think this was because I am using the map in a panel which expands on user interaction instead of being visible on load.
I switched my ng-show to an ng-if and it worked correctly. This is because the map code(I used a directive) will not run until the if condition is true, which allows it to render properly.
*Sorry the fiddle got deleted. I don't remember what I had in it, but it was something like this
<gmap unique="231" center="{{getAddress(item)}}" destination="{{getAddress(item)}}" origin="{{getMyAddress(item)}}" type="roadmap" marker-content="Hello"></gmap>
The important thing is that the google scripts don't start doing their thing until your container element is actually displayed. This is accomplished with the ng-if.
Add the ng-cloak property on your map element or on your directive element.
"The ngCloak directive is used to prevent the Angular html template from being briefly displayed by the browser"
http://docs.angularjs.org/api/ng.directive:ngCloak
map rendered successfully without resize.
Why resize gives you proper map ?
Because browser paints the view again.
How to fix it?
To get a proper layout of the map in any panel which is triggered lately, map has to be painted after the panel is loaded.This can be achieved by (setTimeout) code as mentioned below.
code objective is to trigger map resize event after 60 milli seconds.
setTimeout(function () {
uiGmapIsReady.promise().then(function (maps) {
google.maps.event.trigger(maps[0].map, 'resize');
lat = -37;
lon = 144;
maps[0].map.panTo(new google.maps.LatLng(lat,lon));
var marker = {
id: Date.now(),
coords: {
latitude: lat,
longitude: lon
}
};
$scope.map.markers = [];
$scope.map.markers.push(marker);
console.log($scope.map.markers);
});
}, 60);
Try to resize the map using this code in the controller:
NgMap.getMap().then(function(map){
google.maps.event.addListener(map, "idle", function(){
google.maps.event.trigger(map, 'resize');
});
});
I am trying to display a google static map, which when clicked, will open up a larger iframe, where the user can pan, zoom, etc.
JSFiddle here
Code below:
<div>
<a class="various fancybox.iframe" title="Whitehouse - USA" href="https://maps.google.com/maps?f=d&source=s_d&saddr=&daddr=1600+Pennsylvania+Ave+NW,+White+House,+Washington,+DC+20500&hl=en&geocode=Ca3jx5Eq6BcjFQ6IUQIdG4Ro-ynPaZnjvLe3iTGGOSyaFzTP2g&sll=38.897678,-77.036517&sspn=0.009644,0.01443&g=1600+Pennsylvania+Avenue+Northwest,+Washington,+DC&mra=ls&ie=UTF8&t=m&ll=38.89768,-77.036519&spn=0.008016,0.013733&z=16&output=embed">
<img src="http://maps.googleapis.com/maps/api/staticmap?center=1600+Pennsylvania+Ave+NW,+White+House,+Washington,+DC+20500&markers=1600+Pennsylvania+Ave+NW,+White+House,+Washington,+DC+20500&size=300x300&sensor=false">
</a>
</div>
I have tried to look for the non-javascript documentation relating to the iframe,but haven't come across anything. I would like to add the following to the iframe:
Center on the marker - The JSFiddle appears centered, but the exact same code run on the production site renders an iframe with the marker appearing in the top left.
Remove the marker label "B"
Input my own coordinates from my database - for example... do the same for New York City, Chicago, etc.. However, I have tried changing the daddr (destination address), but am unsure what the other variable stand for (i.e. sll, sspn, g, mra, ll, etc.)
Get directions - insert starting point, and get directions to pre-determined destination
At first a explanation of the parameters you need:
f
has to be d for directions
saddr
the start-address, may be a string(would be geolocated) or a latLng
daddr
the destination-address, may be a string(would be geolocated) or a latLng
ll
where to center the map(latlng) .when ommited, the map will be centered based on the markers
z
the zoom of the map. When ommitted the map will be zoomed based on the direction
output
has to be embed for iframe
A detailed list and explanation of the parameters you'll find at http://www.seomoz.org/ugc/everything-you-never-wanted-to-know-about-google-maps-parameters
However: you should note that none of the parameters is a part of any official API, it may change every day
The issues:
Center on the marker:
the marker could not be centered, because the iframe isn't visible when the map starts loading, unable to determine the size of the iframe . You could use a workaround:
First load a dummy-page into the iframe, when the fancybox is open, load the map.
This can be done by adding this to the fancybox-options:
beforeLoad: function(){
//store the original href for later use
this.oldhref=this.href;
//replace the href with some dummy-page
this.href='wait.htm';
return true;
},
afterLoad:function(){
//load the originally requested page to the iframe
$('.fancybox-iframe').attr('src',this.oldhref);
}
Remove the marker label "B"
there is no option to remove the B, all you can to is replace it with an A .
Therefore you must set the marker as the marker for the start-destination (saddr)
Input my own coordinates from my database
apply the coordinates to saddr or daddr(depending on what it should be, start or destination)
Get directions - insert starting point, and get directions to pre-determined destination
see 3.
Finally: you should consider to create a own map using the Maps-Javascript-API to get a map that you can handle yourself.
We are now trying to build a map library like google/bing/yahoo,we will use it offline.
However I found that I have no idea about how to arange the divs in the page,since there are some many different types of divs.
1) the map tiles (small image 256X256)
2)the overlayer(marker/informationwindow/polygon...)
3)the control.
I have to try to read the html source codes of google and bing and etc. But I found it is difficult to understand them.
For exmaple,this frangment is copyed from another online map site of China.
As you can see,it is just a exmaple for how to adding a marker to the map.
But take the code,there are so many nested divs,most of them have the property of "width:0;height:0",I do not know why?
Since in my opinion,the marker is just an icon,just put it in the page.
Why use so many nested divs and even the "map" tag?
But I think they must have the advantages which I can not find.
Any one can give some suggestions?
Typically you insert a div in HTML when you want to create a block element but there is no more semantically-loaded element available with the correct meaning.
I think the answer to your question is to use just as many div elements as you need for your purposes. Do not add more just because you can. Sometimes you don't need any div elements at all - you can use other more meaningful elements such as img, ul, p, etc. You can sometimes avoid inserting a wrapping div by using CSS to change an inline element such as a into a block element.
If you need more later then add them later. Don't worry about what Google/Bing/Yahoo do. Their requirements are probably different to yours.
Have you looked at the Google Maps sample code and demo gallery?
http://code.google.com/apis/maps/documentation/javascript/demogallery.html
http://code.google.com/apis/maps/documentation/javascript/examples/index.html
I'm not sure how you would use this "offline" considering the sample you provided makes a call to the internet to get the map. Also all of these types of maps rely heavily on javascript and ajax calls to constantly update the map. Do you mean these pages would be secured and not public?
How about you just use maybe a 5x5 grid of divs, move them as they are dragged out of view, and then texture them dynamically with AJAX calls.
If I am understanding you correctly, all of the layers can be thrown on top of each other with z-index.
<div id="control" style="z-index:-1;"></div>
<div id="overlay" style="z-index:-2;"></div>
<div id="map" style="z-index:-3;"></div>
Then you can use each of these divs as containers for different parts of your map.
As you drag 1 div off to, say, the right, then it will automatically bump itself to the left side of your grid and retexture itself (background-image) through an ajax call.
That's what I would do, at least.
Use the Google Maps API you can see an example of custom tiles here: http://code.google.com/apis/maps/documentation/javascript/examples/maptype-base.html
You would need to copy all the files to your computer to be exceccible offline. Your javascript would look something like this:
function CoordMapType() {
}
CoordMapType.prototype.tileSize = new google.maps.Size(256,256);
CoordMapType.prototype.maxZoom = 19;
CoordMapType.prototype.getTile = function(coord, zoom, ownerDocument) {
var div = ownerDocument.createElement('DIV');
div.style.backgroundImage=coord+'.js';
return div;
};
CoordMapType.prototype.name = "Tile #s";
CoordMapType.prototype.alt = "Tile Coordinate Map Type";
var map;
var chicago = new google.maps.LatLng(41.850033,-87.6500523);
var coordinateMapType = new CoordMapType();
function initialize() {
var mapOptions = {
zoom: 10,
streetViewControl: false,
mapTypeId: 'coordinate',
mapTypeControlOptions: {}
};
map = new google.maps.Map(document.getElementById("map_canvas"),
mapOptions);
google.maps.event.addListener(map, 'maptypeid_changed', function() {
var showStreetViewControl = map.getMapTypeId() != 'coordinate';
map.setOptions({'streetViewControl': showStreetViewControl});
});
// Now attach the coordinate map type to the map's registry
map.mapTypes.set('coordinate', coordinateMapType);
}
I can seem to do this for V3 but cannot find any examples for V2
I want to embed the following DIV contents below, ideally keep within a function so that is is easily changed..
function embedLogo() {
return "<a href='http://website.net/?ref=19299'><img src='./images/seestuff.png' /></a>";
}
I would like this in the bottom right and an example of it on v3 is at http://www.planefinder.net
This sorted it for me
http://googlemapsapi.martinpearman.co.uk/articles.php?cat_id=2
i have the following code:
var point0 = new GLatLng(40.786729,-73.972766);
var marker0 = new GMarker(point0);
marker0.value = 0;
GEvent.addListener(marker0, "click", function() {
var myHtml = "<b><a href='http://Photos.Net'><br />01-0001</a></b><br /><br /><img src=http://adam.kantro.net/pics/Apartment/Thumbnails/Apartment-pic001.jpg><br/><br/><br/>";
map.openInfoWindowHtml(point0, myHtml);
});
the issue is that the image shows up outside the bounds of the popup window. Is there anyway to force the popup window to expand to fit this picture and the full html.
This is a pretty common problem with Google maps info windows.
Set the height explicitly on the image tag:
<img height="112" src=http://.../Apartment-pic001.jpg>
Check inherited styles being applied to the info window contents after it has been attached to the map.
Check out the following question:
How to set Google map's marker's infowindow max height?
Have you tried something like
map.openInfoWindowHtml('<div style="width: 20em">...</div>');
I don't believe it can auto size so you have to be cute and specify the width beforehand
also see here