简体   繁体   中英

How can I get a static URL to a map image using the Google Static Maps API?

I'm making a Web-App (still in "Beta") which uses the Flickr API to get information for the photos of a particular Flickr user and generates IPB code to post any of his/her images.

While Flickr now gives you the IPB code to show the image and link back to the photo site directly on its site, my App also has the option of embeding the title, description, select EXIF data, location information, etc. into the post for the IPB forum.

I've most recently added the option to integrate a Google Maps image of the photo's geolocation data into the post by using the Google Static Maps API.

The problem is that the image URL I have is in the following form (including IPB [IMG] tags):

[IMG]http://maps.google.com/maps/api/staticmap?zoom=16&size=600x600&maptype=hybrid&markers=19.387687,-99.251732&sensor=false[/IMG]

Which shows this example image (In practice the image size is user selectable):

替代文字

However, some IPB forums seem to not support dyamic image URLs which gives me a broken image, I'd like to replace the

[IMG]http://maps.google.com/maps/api/staticmap?zoom=16&size=600x600&maptype=hybrid&markers=19.387687,-99.251732&sensor=false[/IMG]

with something like

[IMG]http://maps.google.com/maps/api/staticmap/map0000001.png[/IMG]

which should be supported by all IPB forums. Thanks in advance for your help.

In case you're interested, the most recent "released" version of my Web-App can be found here: http://flickr.argote.mx/ (The changes I mention here are still on local development server).

There are two types of solution as far as I can see:

  1. You create a proxy server to download the images from Google and serve it on nice URLs to the clients. The disadvantage is that you will have to handle a high traffic through your servers (I don't know much about your project you have to decide about performance)

  2. You create a special BBCODE to handle your URLs and you can use that on any IPB forums

+1: You could create a serverside script with nice URLs to redirect to the Google URLs but the problem is you never know how the different browsers will handle it. I suppose they normally don't follow URLs for images inside pages.

+2: Ask Google to support nice URLs ;)

Hope that helps.

Since both Aston's suggestions are out of the question, maybe you can set up a simple script that redirects the request to Google Maps images (instead of a proxy)?

So you can have something like http://my-simple-script.tld/lat,lng have that script redirect to the correct Google Maps static image URL.

You should be able to use a URL shortener service, as long as the service supports simple 301 redirects to image resources. You'd have to try out which ones do.

For example, bit.ly has a REST API. It allows you to make calls like this from within PHP:

http://api.bitly.com/v3/shorten?login=abc&apiKey=123&longUrl={myurl}&format=json 

returning a bit.ly URL that you can use in BBCode.

Edit: According to this JSFiddle , this method works, at least in Chrome and IE8. It would still need scrupulous testing across browsers.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM