Call Google Maps to show corresponding locations according to latitude and longitude

Source: Internet
Author: User

Idea: Pass the latitude value as the parameter to the corresponding parameter value in the Latlon.htm file. Examples are as follows:

Solution One:

1, a total of two pages (Default.aspx and Latlon.htm)

2. Project:

3, default page code:

<%@ Page language= "C #" autoeventwireup= "true" codebehind= "Default.aspx.cs" inherits= "map editor. _default"%>

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">

<title></title>

<script language= "javascript" type= "Text/javascript" >

function Showmap () {

var Long = document.getElementById ("Long"). Value;

var Lat = document.getElementById ("Lat"). Value;

var company = document.getElementById (' company '). Value;

var zoomlevel = 10;

if (long== "" | | lat== "") {

Long = 113.2759952545166;

Lat = 23.117055306224895;

Company = "Guangzhou";

}

var obj = new Object ();

Obj.lat = lat;//Latitude

OBJ.LNG = long;//Longitude

Obj.zoom = Zoomlevel; Zoom level

Obj.ent = Company;

Obj.sdpno = Company;

obj.addr = "Guangdong";

var retVal = window.showModalDialog (

' latlon.htm?_= ' + math.random ()

, obj, ' dialogwidth:800px;dialogheight:450px; '

);

}

</script>

<body>

<form id= "Form1" runat= "Server" >

<div>

<label title= "Enterprise Name" > Enterprise name:</label>

<input type = "Text" id= "Company"/>

<label title= "Longitude" > Longitude:</label>

<input type = "text" id= "Long"/>

<label title= "Latitude" > Latitude:</label>

<input type = "text" id= "Lat"/>

<input type= "button" value= "Show Map" onclick= "Showmap ()"/>

</div>

</form>

</body>

4, latlon.htm page code:

<title> Jingwei Editor </title>

<script type= "Text/javascript" >

var map;

function Sethms (f) {

Degree

var h = parseint (f);

Part

var m = parseint ((parsefloat (f)-parseint (h)) * 60);

Seconds

var s = parseint (((Parsefloat (f)-parseint (h)) * 60-parseint (M)) * 60);

if (m.tostring (). length = = 1) {

m = ' 0 ' + m.tostring ();

}

if (s.tostring (). length = = 1) {

s = ' 0 ' + s.tostring ();

}

var HMS = H + ' degree ' + M + ' min ' + S + ' sec ';

return HMS;

}

function Initialize () {

var obj = window.dialogarguments;

var lat = Obj.lat;

var lng = OBJ.LNG;

var zoom = parseint (obj.zoom);

var ent = obj.ent;

var sdpno = Obj.sdpno;

var addr = obj.addr;

var latlng = new Google.maps.LatLng (lat, LNG);

var myoptions = {

Here the parameters can be multiple parameters, specific reference Mapoptions object

Zoom:zoom,

CENTER:LATLNG,

MapTypeId:google.maps.MapTypeId.ROADMAP

};

Map = new Google.maps.Map (document.getElementById (' Map_canvas '),

Myoptions);

var marker = new Google.maps.Marker ({

You can refer to Markeroptions objects for multiple parameters.

Map:map,

POSITION:LATLNG,

Draggable:true

});

Google.maps.event.addListener (marker, ' click ', Function (event) {

Here the Infowindow parameters can be multiple objects, you can refer to the Infowindowoptions object

var html = ' <div style= ' line-height:20px; > ';

html + + ' <div><font color= ' blue ' > ' + ent + ' </font></div> ';

html + + ' <div><font color= "Gray" size= "1" > License number: ' + sdpno + ' </font></div> ';

html + + ' <div><font color= ' Gray ' size= ' 1 ' > Address: ' + addr + ' </font></div> ';

html + + ' <div><font color= "Red" size= "1" > Longitude: ' + sethms (EVENT.LATLNG.LNG ()) + ' Latitude: ' + sethms (Event.latLng.lat                 () + ' </font></div> '; HTML + = ' </div> ';

var Infowindow = new Google.maps.InfoWindow ({content:html});

Infowindow.open (map, marker);

});

document.getElementById ("Divload"). Style.display = "None";

document.getElementById ("Map_canvas"). Style.display = "";

}

function Loadscript () {

var script = document.createelement ("script");

Script.type = "Text/javascript";

SCRIPT.SRC = "

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.