Passing KML files to Google Maps - javascript

I just became aware of KML files, did some reading and generated my first KML files off of google maps. In my app I am linking to google maps, passing a publicly available file with the intent of opening the KML file on the users Google Maps or Chrome browser (not within my app). Maps, or Google opens, but the kml file data/map isn't loading. To confirm its public, the URL attempts to download the file from my website.
Doing a simple call like:
window.open("https://maps.google.com/maps?q=https://myserver.com/files/maps/testMap.kml")
Maps successfully opens, but I get a "No Results Found" pop up. I do see my URL passed into the query section of the map - and the zoom is in the middle of the ocean off of Africa...and when I zoom to the map location (Tampa FL) nothing is there.
What am I missing here?

Google Maps no longer supports opening a KML file directly on the main page at maps.google.com. You used to be able to enter the URL for a public KML file right in the Google Maps search bar and have it load directly, or load the KML via a URL parameter like you have in your question (?q=http...), but that functionality was turned off some time ago.
Now, to load a KML file on a Google Map, you'll probably need to set up a web page with a Google Maps API instance on it, where you can use the API to load a KML file. If it's a relatively simple KML, you could also try uploading it to a Google My Map, and using the share functionality in there to share a link or get an embed code.

Related

Same kml file on two different servers - one loads in google maps v3 api and the other doesn't. Why?

I am migrating a website to a different server/domain name. There is a custom map application that uses Google Maps Javascript API v3. The kml file that it loads works fine on the old server, but not on the new server. To remove all the variables in my own code, i tried it with Google's JS Fiddle of their demo app here:
https://developers.google.com/maps/documentation/javascript/kml#try-it-yourself
swapping out the url to the kml file, i first use the old path:
http://nhlt.org/webmap/webmap.xml
it works. Then I put in the new url. The webmap.xml file is exactly the same.
http://groundsw.w17.wh-2.com/webmap/webmap.xml
no data is displayed.
Both of those links are publicly accessible if you just paste them into a browser.
Anyone have any clue what I'm missing?
UPDATE:
This is a screenshot of the results from #geocodezip 's fiddle:

Is it possible to control which Google Maps scripts get fetched (JavaScript API)?

So I am using Google Maps for an autocomplete text input for cities. The script I'm calling has an src like this:
https://maps.googleapis.com/maps/api/js?libraries=places&callback=initAutocomplete&types=(cities)
I see in the network tab that this actually downloads quite a few external google scripts:
common.js
util.js
controls.js
places_impl.js
stats.js
Collectively, these scripts are over 100kb... That's equal to the size of my entire application (gzipped). Is this really necessary just for a places autocomplete? Is there any way to pass params into the request url that control what is downloaded?
Those are all scripts which Google Maps JS API need to function properly, to display Map, etc. But if you want ONLY Places Autocomplete, and you don't even want to display the map, then there is a way for you to not download ANY libraries.
Just make a request to Google Places API, something like:
https://maps.googleapis.com/maps/api/place/autocomplete/json?input=TEXT&types=(cities)&language=en&key=YOUR_API_KEY
for autocomplete results every time user inputs something into you search input box (or preferably with some throttling). Google Places API is not part of Google Maps JS API you are using in your project, it's a separate API only for Places.

What constitutes a call to the basic Google Maps JS api?

Just for background, I have an app which runs in both the browser and as a hybrid PhoneGap app, and which uses the Google Maps JS api.
Essentially, users pan and zoom the map and when a 'map idle' event is triggered, the app queries my API based on the current bounds of the idle map.
I'm just trying to find out what constitutes a call to the JS api?
Does one map load/init equal one api call, regardless of how many times a user pans, scrolls and zooms the map?
Or is each pan, scroll and zoom an api call (in other words, every time the map bounds are changed so new tiles need to be loaded?
Or (worst case) is every new tile that needs to be loaded a separate call to the api?
Or something else?
Anyone shed any light on this?
Thx.
As stated in the Google Maps API:
A single map load occurs when:
a map is displayed using the Maps JavaScript API v3 when loaded by a web page or application;
a Street View panorama is displayed using the Maps JavaScript API v3 by a web page or application that has not also displayed a map;
a SWF that loads the Maps API for Flash is loaded by a web page or application; or
a single request is made for a map image from the Static Maps API.
a single request is made for a panorama image from the Street View Image API.
The degree to which a user interacts with a map once it has been loaded has no impact on the usage limits.

my google maps custome marker wont show in my wordpress site

I can't seem to get my custom marker to show in my google custom map! it used to work a few days ago when I was editing on localhost and used an absolute link for it. the site is in wordpress and Im using a custom styled maps api key and still using absolute link for the icon.
page is at: http://www.smugglersrest.com.au/contact/.
custom marker is located at: http://www.smugglersrest.com.au/wp-content/themes/wpsmugglersrest/img/marker.png
I've also got the google maps api stored in the js folder because i wasn't sure how to enqueue external scripts via the functions.php file and the custom parts of the map & marker call stored in another map.js file and call in via the functions.php
can anyone help??
The external file calls to .js files .. mainly the main.js is giving a 403 forbidden error. If you sort that out, I think your marker will show properly.

Google Maps is using javascript to render image or image files?

To use Google Maps API you fetch their api js file with:
<script type="text/javascript"
src="http://maps.google.com/maps/api/js?sensor=set_to_true_or_false">
</script>
Then I use javascript on my page to interact with this API.
I wonder what is going on in the background that I don't see.
Is this file using javascript to render the Google map or is it fetching jpeg files when I zoom in and out?
Id suggest installing Firebug, a plugin for Firefox, that will let you see exactly what is going on that you don't see (click the 'Net' tab).
In short though, yes, Google Maps API uses javascript both to render the map and fetch jpeg files when you zoom in and out.

Categories