How to get the first tile overlay google maps js - google-maps

I'm using Google Maps SDK to show a map on my site. In addition, I'm showing some custom pins using tiles overlays -> https://developers.google.com/maps/documentation/android-sdk/tileoverlay .
I'm inserting an overlay like this:
const tileAdaptor = new SomeAdaptor();
map.overlayMapTypes.insertAt(0, tileAdaptor);
And now, from other part of my code, I want to access that same instance. I was doing it like this:
window.map.overlayMapTypes.je[0];
But, surprisingly, the .je attribute has been renamed! I do not know if that's because it's an internal API or something like that. Now it has been renamed to .td.
So, my question is, is there a way to get that first overlay without using internal APIs?

Don't use undocumented properties, they can (and will) change with any new release of the API.
You need the overlayMapTypes property, which is a MVCArray, which has a getArray method
window.map.overlayMapTypes.getArray[0]

Related

Convert google map v2 custom overlay to v3 custom overlay

I have been doing so much research and yet to find the exact answer to help me. I need to convert my map at http://www.uaf.edu/campusmap/ from V2 to V3 so I can try to combine it with my fusion tables. It uses tiles made by Map Tiler. Is there anyone who can help me out?
I guess you need to port the whole map to V3 and use Custom Map Types.
BTW, you're loading the API twice, once from http://www.uaf.edu/files/campusmap/ and then again from http://www.uaf.edu/files/campusmap/campusmap-122311.html -- which is loaded in an iframe. Probably better to remove one of them, I think you can get rid of the first one.
I think there are two main things you'll need to worry about when converting to v3:
GTileOverlay doesn't exist in v3. You can use Custom Map Types, as per the pp.
To do this, you'll want to make an ImageMapType (see the docs). You'll then need to add this to the Map.overlayMapTypes MVCArray (which will display it above the base map - Map reference).
There's nothing like GDownloadUrl and GXml for downloading and parsing an XML document in v3. You'll need to use a generic library like jQuery to help downloading your marker locations.

Max url length with Google Maps static image

I need to create a static image of google map with several markers, and each marker has a custom icon.
In the Api DOC there is the note: Static Map URLs are restricted to 2048 characters in size. In practice, you will probably not have need for URLs longer than this, unless you produce complicated maps with a high number of markers and paths.
The url is very long.... There is the position for each marker and the URL for the custom icon for each one.
I've already tried with POST request ma it is not supported.
There is another way to create a static map image without max length limitation?
A possible way might be this, but i don't know if is it possible: I've create my custom map using the function in GMaps, and i have added all the markers i need.
There is a way to access in static way to this particular map? so in the url i have to give only the center of the map and other parameters (zoom, ...), but all the markers are already positioned.
Or... another idea... Can i submit the URL of a KML with all markers positioned instead each single marker position+icon url?
FYI, Google recently updated the limit to 8192.
Have you tried using a URL shortener for the icon urls? I believe the static map API will respect services that make URLs shorter... might save you a few characters.
You might wanna check out toopola´s API to help working with Google Static Maps, I am about to make my own attempt.
Another idea
find map area that contains all the markers
divide the map area into rectangular pieces (4 pieces for example)
create image url for each part, but include in url only markers and icons visible on map
show images
Мethod of division depends on the markers position.
Yes, you can definitely do this with the Javascript API.
I have built a few applications using that API. It can be a little tricky to get your head around, but it is pretty good. For what you want to do, it would not be too difficult. If the user has to be able to interact with the map and add pins and such, it starts to get a little more complicated because you have to capture clicks and such.
Does the map its self need to be available as a URL, or does it just need to be embedded on some page and that URL can be used?
The Javascript API will work best if you can embed the map into an existing webpage.

Custom Google Map overlay?

How can you use a custom tileset/overlay on a Google map, like was done here:
http://www.philaplace.org
That is pretty cool, and I would like to experiment with this.
There are a couple different ways to do it. One way is to create a GTileLayer object and implement the getTileURL() to return the URL pointing to your tiles.
But first you'll need an image that's cut properly in the tile format. For starters, I'd recommend you look at MapTiler: http://www.maptiler.org/ It will cut images for you AND generate a GoogleMap with the overlay.
You'll want to look at Google's Overlays (especially Custom Overlays) and Custom Map Types documentation for Version 3 of their Maps API.

Can I change the marker in a Google Maps embedded map (iframe)?

I know I can do it with the Google Maps API, but do you know if there is a way to change the marker in an embedded Google Map?
I want to replace the default "A" button for a "B" button or the marker with just a dot in the middle.
I haven't played around with embedding Google Maps before (I generally go straight to the API for stuff like this). I tried a couple of approaches:
I figured maybe the embed syntax would be the same as the static maps api. So I grabbed a static maps URL, copied the markers param from that and tried sticking it into the iFrame URL. This didn't work so much.
I created a Google MyPlaces and customized the marker to use the one your provided. This created a Test map which had the appropriate marker icon. I then grabbed the embed code and stuck it on a test page and voila!
Actually I had the same problem but didn't use any of the methods above and thought I share:
If you only want a marker as I did but don't want to use API then simply fool google into thinking you want a route planned using the GET tags "saddr" and "daddr"
"saddr" defines your start location (post code , street name+ number, whatever)
ONLY define saddr and leave out daddr and google maps will by default still show the marker for "A" (your start location) exactly where you want it , all in iframe without API.

Do i need use google maps api only to embed litle map with route calculator/display for only one destination?

Well i want to upgrade contact page with dynamic map showing location and give oportunity to calculate route for comapny headquatters. Id it necessery for such simple task use Google api? i mean here generating akey etc? Fo i have any other alternatives to google maps?
There's really no reason to mess with the API at all unless you need to customize the appearance or behavior of gmaps. Why not just use an iframe with a url of:
http://maps.google.com/?q=[you-url-encoded-address-here]
or better yet, set up a textbox and a 'get directions' button to redirect that frame to:
http://maps.google.com/maps?saddr=[their-address]&daddr=[your-address]
edit: this works well in modal dialog if you don't want the google logo sticking out like a sore thumb in your pageflow
You could probably embed directly with a specific URL that will configure it to have the destination you want.
By the way, well written answers are much more likely to receive useful responses here.
You could consider http://www.openlayers.org/ as an alternative to google maps.
In fact open layers can be used to add a Google map, or an OpenStreetMap map or a Bing map, etc.