最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin0浏览0评论

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];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];size=600x600&maptype=hybrid&markers=19.387687,-99.251732&sensor=false[/IMG]

with something like

[IMG].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: / (The changes I mention here are still on local development server).

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./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./maps/api/staticmap?zoom=16&size=600x600&maptype=hybrid&markers=19.387687,-99.251732&sensor=false[/IMG]

with something like

[IMG]http://maps.google./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).

Share Improve this question edited Mar 24, 2011 at 23:30 Argote asked Jan 6, 2011 at 8:50 ArgoteArgote 2,1551 gold badge15 silver badges20 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 4

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.

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./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.

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.

发布评论

评论列表(0)

  1. 暂无评论
ok 不同模板 switch ($forum['model']) { /*case '0': include _include(APP_PATH . 'view/htm/read.htm'); break;*/ default: include _include(theme_load('read', $fid)); break; } } break; case '10': // 主题外链 / thread external link http_location(htmlspecialchars_decode(trim($thread['description']))); break; case '11': // 单页 / single page $attachlist = array(); $imagelist = array(); $thread['filelist'] = array(); $threadlist = NULL; $thread['files'] > 0 and list($attachlist, $imagelist, $thread['filelist']) = well_attach_find_by_tid($tid); $data = data_read_cache($tid); empty($data) and message(-1, lang('data_malformation')); $tidlist = $forum['threads'] ? page_find_by_fid($fid, $page, $pagesize) : NULL; if ($tidlist) { $tidarr = arrlist_values($tidlist, 'tid'); $threadlist = well_thread_find($tidarr, $pagesize); // 按之前tidlist排序 $threadlist = array2_sort_key($threadlist, $tidlist, 'tid'); } $allowpost = forum_access_user($fid, $gid, 'allowpost'); $allowupdate = forum_access_mod($fid, $gid, 'allowupdate'); $allowdelete = forum_access_mod($fid, $gid, 'allowdelete'); $access = array('allowpost' => $allowpost, 'allowupdate' => $allowupdate, 'allowdelete' => $allowdelete); $header['title'] = $thread['subject']; $header['mobile_link'] = $thread['url']; $header['keywords'] = $thread['keyword'] ? $thread['keyword'] : $thread['subject']; $header['description'] = $thread['description'] ? $thread['description'] : $thread['brief']; $_SESSION['fid'] = $fid; if ($ajax) { empty($conf['api_on']) and message(0, lang('closed')); $apilist['header'] = $header; $apilist['extra'] = $extra; $apilist['access'] = $access; $apilist['thread'] = well_thread_safe_info($thread); $apilist['thread_data'] = $data; $apilist['forum'] = $forum; $apilist['imagelist'] = $imagelist; $apilist['filelist'] = $thread['filelist']; $apilist['threadlist'] = $threadlist; message(0, $apilist); } else { include _include(theme_load('single_page', $fid)); } break; default: message(-1, lang('data_malformation')); break; } ?>