<! DOCTYPE html> <Html> <Body> <P id = "demo"> Click the button to get your position: </p> <Button onclick = "getLocation ()"> Try It </button> <Div id = "mapholder"> </div> <Script> Var x = document. getElementById ("demo "); Function getLocation () { If (navigator. geolocation) { Navigator. geolocation. getCurrentPosition (showPosition, showError ); } Else {x. innerHTML = "Geolocation is not supported by this browser .";} } Function showPosition (position) { Var latlon = position. coords. latitude + "," + position. coords. longpolling; Var img_url = "http://maps.googleapis.com/maps/api/staticmap? Center =" + Latlon + "& zoom = 14 & size = 400x300 & sensor = false "; Document. getElementById ("mapholder"). innerHTML = " "; } Function showError (error) { Switch (error. code) { Case error. PERMISSION_DENIED: X. innerHTML = "User denied the request for Geolocation ." Break; Case error. POSITION_UNAVAILABLE: X. innerHTML = "Location information is unavailable ." Break; Case error. TIMEOUT: X. innerHTML = "The request to get user location timed out ." Break; Case error. UNKNOWN_ERROR: X. innerHTML = "An unknown error occurred ." Break; } } </Script> </Body> </Html> |