Google Maps Custom Control positioning -


i trying figure out how position control center of page. when use "bottom_center" centers left end of div center of map. i'd offset center of div in bottom center of map. i've search hours , haven't found info on doing this..

does have idea how or can point me @ resource explain little better?

thanks!

the below modified version of converting latlng/pixel coordinate control

<!doctype html> <html>   <head>     <meta http-equiv="content-type" content="text/html; charset=utf-8" />     <title>latlng coordinates control</title>      <style type="text/css">       #map {         width: 800px;         height: 600px;       }        #latlng-control {         background: #ffc;         border: 1px solid #676767;         font-family: arial, helvetica, sans-serif;         font-size: 0.7em;         padding: 2px 4px;         position: absolute;       }     </style>      <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>      <script type="text/javascript">  function degtodms(dec) {      var deg = math.floor(math.abs(dec));     var min = math.floor((math.abs(dec)-deg)*60);     var sec = (math.round((((math.abs(dec) - deg) - (min/60)) * 60 * 60) * 100) / 100 ) ;      var len = string(deg).length     deg = array(3 + 1 - len).join('0') + deg;     var len = string(min).length     min = array(2 + 1 - len).join('0') + min;     var len = string(sec).length     sec = array(5 + 1 - len).join('0') + sec;      deg = dec < 0 ? '-' + deg : deg;          var dec_min = (min*1.0 + (sec/60.0));      var dms  = deg + '&deg ' + dec_min.tofixed(3) + '\'';     return dms; }         function latlngcontrol(map) {          this.node_ = this.createhtmlnode_();         map.controls[google.maps.controlposition.bottom_center].push(this.node_);         this.setmap(map);         this.set('visible', false);       }        latlngcontrol.prototype = new google.maps.overlayview();       latlngcontrol.prototype.draw = function() {};        latlngcontrol.prototype.createhtmlnode_ = function() {         var divnode = document.createelement('div');         divnode.id = 'latlng-control';         divnode.index = 100;         return divnode;       };        latlngcontrol.prototype.visible_changed = function() {         this.node_.style.display = this.get('visible') ? '' : 'none';         //this.node_.style.floatright  = '100px';         };        latlngcontrol.prototype.updateposition = function(latlng) {         var dmslat = degtodms(latlng.lat().tofixed(4));         var dmslon = degtodms(latlng.lng().tofixed(4));         this.node_.innerhtml = 'mouse position: ' +  dmslat + ', ' + dmslon;           };        function init() {         var centerlatlng = new google.maps.latlng(37.748582,-122.418411);         var map = new google.maps.map(document.getelementbyid('map'), {           'zoom': 10,           'center': centerlatlng,           'maptypeid': google.maps.maptypeid.roadmap         });          var latlngcontrol = new latlngcontrol(map);          google.maps.event.addlistener(map, 'mouseover', function(mevent) {           latlngcontrol.set('visible', true);         });         google.maps.event.addlistener(map, 'mouseout', function(mevent) {           latlngcontrol.set('visible', false);         });         google.maps.event.addlistener(map, 'mousemove', function(mevent) {           latlngcontrol.updateposition(mevent.latlng);         });       }        google.maps.event.adddomlistener(window, 'load', init);     </script>   </head>   <body>     <h2>latlng coordinate control</h2>     <div id="map"></div>   </body> </html> 

for little while there thought might have uncovered bug in google api!... no, alas have been easy ;-)

your basic problem here when sticking div latlngcontrol onto map its' width 0. goes meant , when put text div expands out point. if grab map , pan mouse, you'll notice latlngcontrol reposition way intended. quick fix, make modification:

  function latlngcontrol(map) {       this.node_ = this.createhtmlnode_();      var dmslat = degtodms(map.getcenter().lat().tofixed(4));      var dmslon = degtodms(map.getcenter().lng().tofixed(4));      this.node_.innerhtml = 'mouse position: ' +  dmslat + ', ' + dmslon;      map.controls[google.maps.controlposition.bottom_center].push(this.node_);      this.setmap(map);   // this.set('visible', false);  <---keep simple   } 

if really want page load latlng div invisible you'll need futz around little more - hack i'm thinking of programmatically pan map & forth when first move mouse on map - when shake tv remote make work properly... that's icky.

also this

position: absolute; 

in css redundant. , this

divnode.index = 100; 

...i know you're possibly trying position latlng div above google legal blurb it's not obscured. , can done, have attach div page directly , not via map.


Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -