`
zcw_java
  • 浏览: 296830 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

利用JS获取经纬度,定位html地图

 
阅读更多
<!--
  copyright (c) 2009 Google inc.
  You are free to copy and use this sample.
  License can be found here: http://code.google.com/apis/ajaxsearch/faq/#license
-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml">
  <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
    <title>Google Maps API Sample</title>
    <style type="text/css">
      @import url("http://www.google.com/uds/css/gsearch.css");
      @import url("http://www.google.com/uds/solutions/localsearch/gmlocalsearch.css");
    </style>
    <script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAA1XbMiDxx_BTCY2_FkPh06RRaGTYH6UMl8mADNa0YKuWNNa8VNxQEerTAUcfkyrr6OwBovxn7TDAH5Q"
      type="text/javascript"></script>
    <script src="http://www.google.com/uds/api?file=uds.js&amp;v=1.0" type="text/javascript"></script>

    <script src="http://www.google.com/uds/solutions/localsearch/gmlocalsearch.js" type="text/javascript"></script>
    function initialize() {
      if (GBrowserIsCompatible()) {
        // Create and Center a Map36.1019825, 103.6055232)
        var map = new GMap2(document.getElementById("map_canvas"));
        map.setCenter(new GLatLng(36.1019825, 103.6055232), 13);
        map.addControl(new GLargeMapControl());
        map.addControl(new GMapTypeControl());
    
        // bind a search control to the map, suppress result list
        map.addControl(new google.maps.LocalSearch(), new GControlPosition(G_ANCHOR_BOTTOM_RIGHT, new GSize(10,20)));
		
      }
    }
    GSearch.setOnLoadCallback(initialize);

    </script>
  </head>
  <body onload="initialize()" onunload="GUnload()" style="font-family: Arial;border: 0 none;">
    <div id="map_canvas" style="width: 500px; height: 300px"></div>
  </body>
</html>


通过地址获取经纬度
<%@ page language="java" errorPage="/error.jsp" pageEncoding="UTF-8" contentType="text/html;charset=utf-8" %>
<%@ include file="/common/taglibs.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<link href="/styles/ui_common_style.css" rel="stylesheet" type="text/css" />
<script src="http://ditu.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAA_zi7L6cpe4J1WluhuKve0BT1V3LlcAyZs_rJnbX4McegqDYCtBT4TtSQRAm_03EocwOwlLLyaxG2zg" type="text/javascript"></script>
<script type="text/javascript" src="/scripts/jquery.js"></script>
<script src="/scripts/validate.js" type="text/javascript"></script>
<script src="/scripts/ssjl_Registered.js" type="text/javascript"></script>
<script src="/scripts/message.js" type="text/javascript"></script>
<script type="text/javascript">
    $(function(){
        var lonNum;
        var latNum;
        $(":input[name=\'submit\']").click(function(){
            if(Detect()){
            var address=document.getElementById('Address').value;
            var geocoder = new GClientGeocoder();
               geocoder.getLatLng(
                address,
                function(point) {
                    var mycars=new Array()
                    mycars = new String(point).split(",");
                    latNum = mycars[0].substring(1);
                    lonNum = mycars[1].substring(1,mycars[1].length-1);
                    var $form = $("#user").serialize();
                        $.ajax({
                            type:"POST",
                            url:"cpRegistered.aa?op=1&lonNum="+lonNum+"&latNum="+latNum,
                            dataType:"text",
                            data:$form,
                            asyns:false,
                            success:function(res){
                                if(res=="emailFail"){
                                    alert("此邮箱已经有人使用,请更换后在试试!");
                                }else if(res=="200"){
                                     open_message("注册成功");
                                     setTimeout(function(){
                                         location.href="cpManagerInit.ca";
                                     },1800)
                                }else{
                                    open_message("注册失败");
                                }
                            }
                        })
                    }
                );
            }
        })
    })    
</script>
</head>
<body style="overflow-x: hidden; overflow-y: auto">
  <div class="frame">
    <!--top part begin-->
    <div class="txt_title">新建商家信息</div>
    <form id="user">
    <div class="tooltab">
	  <div class="nowrap left">
        <input class=" wd_50 btn" type="button" value="提交" name="submit">
	    <input class=" wd_50 btn" type="reset" value="重置" name="reset">
	  </div>

	  <div class="clr">&nbsp;</div>

    </div>
	<!--top part end-->

	<div class="EditorBody">

	  <div style=" width:100%;height:100%;overflow: hidden;">

	    <div class="EditorBlock" style=" width:860px;height:auto;overflow-x: hidden; overflow-y: auto;">



		    <fieldset id="BusinessBasicInformation">

		      <div class="rowOne nowrap">
		        <div class="secrowOne">
		          <label><span class="labelTitle">联系人名称:</span>
                      <input id="Contact" class="text reqd Contact" type="text" title="Enter your Contact"  name="extAttributes.attr4" onblur="Validation(this);" value="联系人*" onfocus="Alt(this);"/>                      
			      </label>
		        </div>

			    <div class="secrowTwo">
		          <label><span class="labelTitle">联系人电话:</span>
                      <input id="ContactPhone" class="text reqd ContactPhone" type="text" title="Enter your Contact Phone" name="phoneNumber" onblur="Validation(this);"  value="联系人电话*" onfocus="Alt(this);"/>			        
			      </label>
		        </div>

			    <div class="clr"></div>

		      </div>


		      <div class="rowTwo nowrap">

			    <div class="secrowOne">
		          <label><span class="labelTitle">联系人邮箱:</span>
			       <input id="ContactE-mail" class="text reqd ContactE-mail" type="text" title="Enter your Contact E-mail" name="email" onblur="Validation(this);" value="联系人邮箱*" onfocus="Alt(this);"/>
			      </label>
		        </div>

			    <div class="secrowTwo nowrap">
		          <label><span class="labelTitle">商家名称:</span>
		            <input id="BusinessName" class="text reqd BusinessName" type="text" title="Enter your Business Name"  name="displayName" onblur="Validation(this);" value="商家名称*" onfocus="Alt(this);"/>
			      </label>
		        </div>

			    <div class="clr"></div>

		      </div>

		    </fieldset>

		    <fieldset id="BusinessBasicInformation_2">

		      <div class="rowThree nowrap">

			    <div class="secrowOne">
		          <label><span class="labelTitle">商家介绍:</span>
                    <textarea id="BusinessIntroduction" class="text reqd BusinessIntroduction" type="text" rows="3"  name="extAttributes.attr5" onblur="Validation(this);" value="商家介绍*" onfocus="Alt(this);"></textarea>
			      </label>
		        </div>

			    <div class="clr"></div>

		      </div>

		      <div class="rowFour nowrap">

			    <div class="secrowOne">
		          <label><span class="labelTitle">商家类型:</span>
			        <select id="BusinessType"  class="text reqd BusinessType" name="extAttributes.attr2" style="display: block;>
                        <option value="0" class="text">请选择类型</option>
                        <c:forEach items="${requestScope.serviceType}" var="types">
                             <option value="${types.name}" class="text">${types.name}</option>
                        </c:forEach>
                    </select>
			      </label>
		        </div>

			    <div class="clr"></div>

		      </div>

		    </fieldset>

		    <fieldset id="BusinessAddress">

		      <div class="rowFive nowrap">

		        <div class="secrowOne">
		          <label><span class="labelTitle">所在国家名称:</span>
			        <input id="CountryName" type="text" disabled="true"  class="text reqd CountryName" value="中国" />
			      </label>
		        </div>

			    <div class="secrowTwo">
		          <label><span class="labelTitle">所在省份名称:</span>
			        <select id="ProvinceName"  class="text reqd ProvinceName" name="store_province" title="Enter your Province Name" onchange="Validation(this);">
                    </select>
			      </label>
		        </div>

                <div class="secrowThree">
		          <label><span class="labelTitle">所在城市名称:</span>
			        <select id="CityName"  class="text reqd CityName" name="store_city" title="Enter your CityName" onchange="Validation(this);">
                        <option value="东城">东城</option>
                  </select>
			      </label>
		        </div>
			    <div class="clr"></div>

		      </div>


		      <div class="rowSix nowrap">

			    <div class="secrowOne">
		          <label><span class="labelTitle">商家地址:</span>
			        <input id="Address" class="text reqd Address" type="text" title="Enter your Address" name="store_address" onblur="Validation(this);" value="商家地址*" onfocus="Alt(this);"/>
			      </label>
		        </div>

			    <div class="secrowTwo">
		          <label><span class="labelTitle">邮政编码:</span>
		            <input id="ZipCode" class="text reqd ZipCode" type="text" title="Enter your Zip Code"  name="store_postalCode" onblur="Validation(this);" value="邮政编码*" onfocus="Alt(this);"/>
			      </label>
		        </div>

			    <div class="clr"></div>

		      </div>
			</fieldset>



	    </div>

	    <div class="tooltab tooltab_bottom">
        <input class=" wd_50 btn" type="button" value="提交" name="submit">
	    <input class=" wd_50 btn" type="reset" value="重置" name="reset">
	    </div>
	  </div>
        </div>
	</form>
    </div>
  </div>
</body>
</html>

http://www.cnblogs.com/liongis/archive/2011/03/01/1967593.html
http://code.google.com/intl/zh-CN/apis/maps/faq.html#keysystem
分享到:
评论
1 楼 yahier 2014-05-05  
没帮助。。。。。。

相关推荐

Global site tag (gtag.js) - Google Analytics