Google static map API implementation code

Source: Internet
Author: User

Copy codeThe Code is as follows:
<! DOCTYPE html>
<Html>
<Head>
<Title> Google static map API </title>
<Style type = "text/css">
# DivStaticMap span
{
Color: Gray;
Font-size: 12px;
}
# DivStaticMap. sel
{
Width: 130px;
}
</Style>
<Script type = "text/javascript">
Function getObj (id ){
Return document. getElementById (id );
}

Function getStaticMap (){
Var url = 'HTTP: // maps.google.com/maps/api/staticmap? Center = ';
If (getObj ('chkusenum'). checked ){
Url + = encodeURI (getObj ('txtx '). value) +', '+ encodeURI (getObj ('txty'). value );
}
Else {
Url + = encodeURI (getObj ('txtcenter'). value );
}
Url + = '& zoom =' + getObj ('txtzoom '). value;
Url + = '& size =' + getObj ('txtwidth'). value + 'X' + getObj ('txtheight '). value;
Url + = '& format =' + getObj ('selimagetype '). options [getObj ('selimagetype'). selectedIndex]. text;
Url + = '& maptype =' + getObj ('selmaptype'). value;
Var trs = getObj ('tdflaglist'). getElementsByTagName ('tr ');
For (var I = 1; I <trs. length; I ++ ){
Var txtFlagAddress = trs [I]. getElementsByTagName ('input') [0];
If (txtFlagAddress. value = ''){
Continue;
}
Var selFlagColor = trs [I]. getElementsByTagName ('select') [0];
Var selFlagSize = trs [I]. getElementsByTagName ('select') [1];
Var txtFlagLabel = trs [I]. getElementsByTagName ('input') [1];
Url + = '& markers = size:' + selFlagSize. value;
Url + = '| color:' + selFlagColor. options [selFlagColor. selectedIndex]. text;
Url + = '| label:' + txtFlagLabel. value;
Url + = '|' + encodeURI (txtFlagAddress. value );
}
Url + = '& sensor = false ';

GetObj ('txtimageurl'). value = url;
GetObj ('imgmap'). src = url;
GetObj ('imgmap'). style. display = 'block ';
}

Function addMapFlag (o ){
Var tr = o. parentNode. parentNode;
Var newTr = tr. parentNode. appendChild (tr. cloneNode (true ));
Var aList = newTr. getElementsByTagName ('A ');
AList [0]. style. display = 'inline ';
AList [1]. style. display = 'none ';
NewTr. getElementsByTagName ('input') [0]. value = '';
Return false;
}

Function delMapFlag (o ){
Var tr = o. parentNode. parentNode;
Tr. parentNode. removeChild (tr );
Tr = null;
Return false;
}

Function chkUseNum_onclick (o ){
GetObj ('txtx '). disabled =! O. checked;
GetObj ('txty '). disabled =! O. checked;
}
</Script>
</Head>
<Body>
<! --
Reference: http://code.google.com/intl/zh-CN/apis/maps/documentation/staticmaps/
Note that no key is required for the next API!
Use the SRC address of IMG to access the Google address!
Http://maps.google.com/maps/api/staticmap? Center = Xi'an, clock tower & zoom = 14 & size = 512x512 & maptype = hybrid & sensor = false
-->
<Div id = "divStaticMap" style = "font-size: 14px;">
<Table>
<Tr>
<Td style = "vertical-align: top; padding-top: 5px;"> center location: </td>
<Td> <input id = "txtCenter" type = "text" value = "Xi'an, Bell Tower"/> <br/>
<Input id = "chkUseNum" type = "checkbox" onclick = "chkUseNum_onclick (this);"/> <label for = "chkUseNum"> Use latitude and longitude: </label> <br/>
<Input id = "txtX" type = "text" value = "0" disabled style = "width: 50px;"/> X
<Input id = "txtY" type = "text" value = "0" disabled style = "width: 50px;"/>
<Span> (latitude-180 ~ 180 longitude-90 ~ 90) </span>
</Td>
</Tr>
<Tr>
<Td> zoom level: </td>
<Td> <input id = "txtZoom" type = "text" value = "11" style = "width: 50px;"/> <span> (0-21) </span> </td>
</Tr>
<Tr>
<Td> image size: </td>
<Td> <input id = "txtWidth" type = "text" value = "500" style = "width: 50px;"/> X
<Input id = "txtHeight" type = "text" value = "500" style = "width: 50px;"/> <span> (less than 640x640) </span> </td>
</Tr>
<Tr>
<Td> image format: </td>
<Td> <select id = "selImageType" class = "sel">
<Option> jpg </option>
<Option> png </option>
<Option> png32 </option>
<Option> gif </option>
<Option> jpg-baseline </option>
</Select> </td>
</Tr>
<Tr>
<Td> map type: </td>
<Td> <select id = "selMapType" class = "sel">
<Option value = "roadmap"> standard Road Map </option>
<Option value = "satellite"> satellite images </option>
<Option value = "terrain"> natural terrain </option>
<Option value = "hybrid"> satellite and Road Map </option>
</Select> </td>
</Tr>
<Tr>
<Td style = "vertical-align: top; padding-top: 5px;"> map Tag: </td>
<Td id = "tdFlagList">
<Table style = "border: solid 1px gray;">
<Tr style = "font-size: 12px; color: Gray; background-color: # fef;">
<Td> location (address or latitude and longitude are separated by |) </td>
<Td> MARK (A-Z, 0-9) </td>
<Td> color </td>
<Td> size </td>
<Td> operation </td>
</Tr>
<Tr>
<Td> <input type = "text" value = "Xi'an, Bell Tower"/> </td>
<Td> <input type = "text" value = "S" style = "width: 80px;"/>
</Td>
<Td> <select>
<Option style = "background-color: red;"> red </option>
<Option style = "background-color: black;"> black </option>
<Option style = "background-color: brown;"> brown </option>
<Option style = "background-color: green;"> green </option>
<Option style = "background-color: purple;"> purple </option>
<Option style = "background-color: yellow;"> yellow </option>
<Option style = "background-color: blue;"> blue </option>
<Option style = "background-color: gray;"> gray </option>
<Option style = "background-color: orange;"> orange </option>
<Option style = "background-color: white;"> white </option>
</Select> </td>
<Td> <select>
<Option value = "mid"> moderate </option>
<Option value = "small"> small </option>
<Option value = "tiny"> very small </option>
</Select> </td>
<Td>
<A style = "color: Red; font-size: 12px; display: none;" href = "#" onclick = "delMapFlag (this);"> Delete </a>
<A style = "color: Blue; font-size: 12px;" href = "#" onclick = "addMapFlag (this);"> added </a> </td>
</Tr>
</Table>
</Td>
</Tr>
<Tr>
<Td> </td>
<Td> <input type = "button" value = "get" onclick = "getStaticMap ();"/>
</Td>
</Tr>
</Table>
<Hr/>
Image address: <input id = "txtImageUrl" type = "text" style = "width: 500px;"/> <br/>

</Div>
<Script type = "text/javascript">
GetStaticMap ();
</Script>
</Body>
</Html>

DEMO code: http://demo.jb51.net/js/googleStaticMap/index.html

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.