google maps and scopes within greasemonkey - javascript

I am writing a greasemonkey script that will allow its users to click a button and view a popup map. I am going to try and use google maps for actually creating the map and plotting a few points. I have a couple of questions about this however.
First, would using script to create an iframe within my popup div that calls a script from my server have to use an api key for my server, or would it have to be a key for the site the greasemonkey script will run on?
Secondly, if this fails is there a way to use JS to plot points on an image like image magick does for PHP?

If you use Google Maps Javascript API V3 you don't need API keys anymore.
To generate images with javascript, you could use the new <canvas> element: https://developer.mozilla.org/en/canvas_tutorial

Related

OpenLayers 3 - Bing maps won't load in Windows App

I'm trying to load Bing maps using OpenLayers 3 in a Windows application. However, i'm facing the following error:
APPHOST9601: Can’t load <https://dev.virtualearth.net/REST/v1/Imagery/Metadata/AerialWithLabels?uriScheme=https&include=ImageryProviders&key=Ao9wqOnCiDvABI4LnDdguzUE0lbF1PiAcDSYHkKdezCage1xuUXY2emXAuHzdOUX&jsonp=olc_9>. An app can’t load remote web content in the local context.
I've tried adding the following line to the ContentUriRules in the manifest without success:
<Rule Match="https://dev.virtualearth.net/*" Type="include" />
I do not want to load the OpenLayers map in an iframe, because then I have to use the postMessage function to pass data to the iframe from classes outside the iframe. Is there a workaround to get the Bing maps working?
Without using an iframe, the Windows app will not let you to load any external script references. I recommend taking a look at using Apache Cordova which hosts everything in an iframe and also gives you access to the native features of the Windows app.
I've managed to fix the issue by adding a function to the OL library that loads an url containing JSON data without using JSONP. Now the data is seen as JSON instead of Javascript (inherent to JSONP) and thus the security restrictions do not apply anymore.
The loading time can be long for this request. I wonder if we could avoid making it every time the window is refreshed.
I also have a problems with stereographic projection but otherwise it's OK.

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.

Google maps API v3 - How are client loads detected?

I have a small and low key website what features Google Maps using the v3 Javascript API.
Not that I am expecting to get over 25,000 loads per day, but how does Google detect people loading the map on my site? My site uses the the following code http://maps.google.com/maps/api/js?sensor=false without any API key, and as it is rendered in the clients browser, how does Google relate it to my site?
Is the loads worked out through the http headers/referrers or are the loads based on how many times each client/IP loads the map?
In essence, the code for the map is rendered on my clients/users browsers and thus how do Google know how many people are using the map on my site?
Finally; although I have Google web master tools; is it worth creating & using a API key, or will it just make it possible for Google to track how many people are using the map on my site and thus apply the limit of 25,000?
The API sends a request to google which contains the URI of the page that contains the map(when you inspect the network-traffic inside the dev-tools you'll see a request to https://maps.googleapis.com/maps/api/js/QuotaService.RecordEvent ) . This request will be sended when a Maps-instance has been created successfully.
The benefit of using a key: google is able to contact you when there are issues(e.g. may send a notice when you have reached any limits and give you a chance to react/solve the issue before they restrict the API-access for your domain/account).

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.

How to make a Google Maps API (.js) file a part of a widget for Mobiles

I would like to create a Web App for device. For that I would have some script being stored on device, instead of downloading them all time when I start application. As far as I saw including a GoogleMaps API makes some additional request for javascript files. Is there any way of having all of them taken directly from local store? Or is this always have to refeer to google web address? Thanks for any answers here!
No, you always must load them from the Google site. They offer no way to run Google Maps locally. The GMaps scripts are generated on the fly, based upon (among others, I'm sure) the HTTP_REFERER header of the request. That's how they can bind an API key to a specific website.

Categories