problema Geocoder

55 views
Skip to first unread message

celso malheiro

unread,
Nov 21, 2011, 3:38:41 PM11/21/11
to google-map...@googlegroups.com
Eu estou com um problema com o código abaixo:

geocoder.geocode retorna 
   status = google.maps.GeocoderStatus.OK
   results[0].geometry.location = ROOFTOP
   results[0].formatted_address = 'R.Voluntários da Pátria, Botafogo, etc...
   results[0].geometry.location.LatLng.lat()  = undefined 
   results[0].geometry.location.LatLng.lngt() = undefined 
como isso é possível?



I've got a problem with the code below:

geocoder.geocode returns
    status = google.maps.GeocoderStatus.OK
    results [0]. geometry.location = ROOFTOP
    results[0].formatted_address = 'R.Voluntários da Pátria, Botafogo, etc...
    results [0]. geometry.location.LatLng.lat () = undefined
    results [0]. geometry.location.LatLng.lngt () = undefined
how is this possible?
   

<!DOCTYPE html>                                                                                                                         
<html>                                                                                                                                  
  <head>                                                                                                                                
    <meta http-equiv="content-type" content="text/html; charset=utf-8"/>                                                                
    <style type="text/css">                                                                                                             
      html { height: 100% }                                                                                                             
      body { height: 100%; margin: 0; padding: 0 }                                                                                      
      #map { height: 100% }                                                                                                             
    </style>                                                                                                                            
    <script type="text/javascript"                                                                                                      
        src="http://maps.googleapis.com/maps/api/js?sensor=false">                                                                      
    </script>                                                                                                                           
    <script type="text/javascript">                                                                                                     
                                                                                                                                        
var map;                                                                                                                                
var centerLongitude = '-47.93000';                                                                                                    
var centerLatitude = '-15.78000';                                                                                                     
var geocoder;                                                                                                                           
                                                                                                                                        
function codeAddress(endereco) {                                                                                                        
    geocoder.geocode( { address: endereco}, function(results, status) {                                                                 
      if (status == google.maps.GeocoderStatus.OK) {                                                                                    
        alert(results[0].formatted_address);                                                                                            
        alert(results[0].geometry.location.LatLng.lat());                                                                               
        alert(results[0].geometry.location.LatLng.lng());                                                                               
        var latlng = results[0].geometry.location;                                                                                      
        map.setCenter(latlng);                                                                                                          
        var marker = new google.maps.Marker({                                                                                           
            map: map,                                                                                                                   
            position: latlng,                                                                                                           
            draggable: true                                                                                                             
        });                                                                                                                             
      } else {                                                                                                                          
        alert("Geocode was not successful for the following reason: " + status);                                                        
      }                                                                                                                                 
    });                                                                                                                                 
  }                                                                                                                                     
                                                                                                                                        
function init() {                                                                                                                       
    // o mapa                                                                                                                           
        var latlng = new google.maps.LatLng(centerLatitude, centerLongitude);                                                           
        var myOptions = {                                                                                                               
          zoom: 12,                                                                                                                     
          center: latlng,                                                                                                               
          mapTypeId: google.maps.MapTypeId.HYBRID                                                                                       
        };                                                                                                                              
        var map = new google.maps.Map(document.getElementById("mapa"),myOptions);                                                       
    geocoder = new google.maps.Geocoder();                                                                                              
    codeAddress('RUA VOLUNTARIOS DA PATRIA BOTAFOGO RIO DE JANEIRO RJ');                                                          
}                                                                                                                                       
                                                                                                                                        
    </script>                                                                                                                           
  </head>                                                                                                                               
                                                                                                                                        
  <body style="margin: 0; padding: 0; width: 100%; height: 100%;" onload="init()">                                                      
    <form name="FrmCnes">                                                                                                               
      <div id="mapa" style="width:100%; height:100%"></div>                                                                             
    </form>                                                                                                                             
                                                                                                                                        
  </body>                                                                                                                               
</html>                                                                                                                                 

JKurtock

unread,
Nov 21, 2011, 6:05:14 PM11/21/11
to Google Maps JavaScript API v3
lngt()?

While this typo might just be in your email, it underscores why you
are more likely to get (useful) help if you provide the link to your
map. Then someone could find the typo immediately, rather than just
guessing that you made one.

On Nov 21, 12:38 pm, celso malheiro <celsomalhe...@gmail.com> wrote:
> Eu estou com um problema com o código abaixo:
>
> geocoder.geocode retorna
>    status = google.maps.GeocoderStatus.OK
>    results[0].geometry.location = ROOFTOP
>    results[0].formatted_address = 'R.Voluntários da Pátria, Botafogo, etc...

>    results[0].geometry.location.LatLng.lat()  =* undefined*
>    results[0].geometry.location.LatLng.lngt() =* undefined*


> como isso é possível?
>
> I've got a problem with the code below:
>
> geocoder.geocode returns
>     status = google.maps.GeocoderStatus.OK
>     results [0]. geometry.location = ROOFTOP
>     results[0].formatted_address = 'R.Voluntários da Pátria, Botafogo,
> etc...

>     results [0]. geometry.location.LatLng.lat () = *undefined*
>     results [0]. geometry.location.LatLng.lngt () = *undefined*

celso malheiro

unread,
Nov 21, 2011, 7:00:00 PM11/21/11
to google-map...@googlegroups.com
Hi.J, you're right. Page's link : http://cnes.datasus.gov.br/download/celsol/myindex.html

regards

2011/11/21 JKurtock <jkur...@gmail.com>
--
You received this message because you are subscribed to the Google Groups "Google Maps JavaScript API v3" group.
To post to this group, send email to google-map...@googlegroups.com.
To unsubscribe from this group, send email to google-maps-js-a...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-maps-js-api-v3?hl=en.


Rossko

unread,
Nov 21, 2011, 7:51:15 PM11/21/11
to Google Maps JavaScript API v3
>    results[0].geometry.location.LatLng.lat()  =* undefined*

results[0].geometry.location is a LatLng object already.
It doesn't have a LatLng method or property.
Try results[0].geometry.location.lat()

Also note your 'map' variable is locally defined within your init()
function, and won't be available to your geocoding callback when the
results come back later. Put it in global scope, perhaps.

celso malheiro

unread,
Nov 22, 2011, 7:29:35 AM11/22/11
to google-map...@googlegroups.com
Thanks, Rossko!

2011/11/21 Rossko <ros...@culzean.clara.co.uk>
--
You received this message because you are subscribed to the Google Groups "Google Maps JavaScript API v3" group.
Reply all
Reply to author
Forward
0 new messages