Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

215
Views
Google Map no está visible porque el valor dinámico se muestra indefinido

A continuación se muestra mi código. He declarado las variables globales longitude y latitude pero si quiero imprimir la alerta de longitud o latitud, entonces el valor solo funciona cuando lo agrego dentro de navigator.geolocation.getCurrentPosition(function(position) { y si agrego alerta afuera como function initMap() , luego se muestra indefinido.

 var initMap; var map; var longitude; var latitude; navigator.geolocation.getCurrentPosition(function(position) { console.log("I'm at " + position.coords.latitude + ", " + position.coords.longitude); $('body').attr('data-long', position.coords.longitude); $('body').attr('data-lat', position.coords.latitude); var map; var longitude = $('body').attr("data-long"); var latitude = $('body').attr("data-lat"); // alert(longitude); }); alert(latitude); function initMap() { map = new google.maps.Map(document.getElementById('map'), { center: { lat: latitude, lng: longitude }, zoom: 8 }); } var marker_origin = new google.maps.Marker({ map: map, title: "you are here", icon: { scaledSize: { width: 50, height: 50 }, url: "http://maps.google.com/mapfiles/kml/paddle/blu-blank.png" }, position: { lat: latitude, lng: longitude } }); {% for row in hubdb_table_rows(table_id) %} var marker_{{ row.hs_id }} = new google.maps.Marker({ map: map, position: {lat: {{ row.location["lat"] }}, lng: {{ row.location["lon"] }}}, title: '{{ row.name }}', icon: { scaledSize: { width: 40, height: 40 }, url: "http://maps.google.com/mapfiles/kml/shapes/dining.png" } }); marker_{{ row.hs_id }}.addListener('click', function() { new google.maps.InfoWindow({ content: '<div> {{ row.name }} is {{ row.location|geo_distance(request.query_dict['lat'], request.query_dict['lon'], "mi")|round(3) }} miles away</div>' }).open(map, marker_{{ row.hs_id }}); }); {% endfor %}
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!