Visualizzazione dei risultati da 1 a 3 su 3
  1. #1
    Utente di HTML.it
    Registrato dal
    Jan 2012
    Messaggi
    154

    [JAVASCRIPT] Reverse geocoding/ Estrapolare variabile da funzione

    Ciao,

    avrei bisogno di risalire alle coordinate di un posto sapendo il nome dello stesso. Ho trovato una funzione:

    codice:
    function check_city()
    {
    
    var place =  $("#city").val();
    geocoder = new GClientGeocoder();
    geocoder.getLatLng(place, function(point) {
        if (!point) {
    
            alert("Place not found. Retry!");
    		$("#city").val("");
    		$('#city').focus(); 	}
            
    	else {
    		var lat = point.y;
    		var long = point.x;  }
    });
    }
    Avrei bisogno di usare lat e long in un altra funzione. Ossia la seguente:

    codice:
    $(function() { 
    $("#bottone").click(function() {
    ControllaForm()}); 
    });
    function ControllaForm(){ 
    var name = $("#name").val(); 
    var last = $("#last").val(); 
    var email = $("#email").val(); 
    var city = $("#city").val(); 
    var day = $("#day").val(); 
    var month = $("#month").val(); 
    var year = $("#year").val(); 
    var password = $("#password").val(); 
    var sex = $("#sex").val(); 
    
    var dataString = 'name='+ name + '&last=' + last + '&password=' + password + '&sex=' + sex + '&email=' + email + '&city=' + city + '&giorno=' + day + '$mese=' + month + '&anno=' + year + '&lat=' + lat + '&long=' + long; 
    if(name=='' || email=='' || password=='' || sex=='' || city=='' || day=='' || month=='' || year=='') { 
    $('.success').fadeOut(200).hide(); 
    $('.error').fadeOut(200).show(); 
    } 
    else 
    {
    $.ajax({ 
    type: "POST", 
    url: "register.php", 
    data: dataString, 
    success: function(){ 
    $('.success').fadeIn(200).show(); 
    $('.error').fadeOut(200).hide(); 
    } 
    }); 
    }
    }
    Tuttavia le variabili sono dentro la funzione quindi non le rileva. C'è qualcuno che sa aiutarmi? :/ Grazie
    Mess with the best die like the rest.

  2. #2
    Moderatore di Annunci siti web, Offro lavoro/collaborazione, Cerco lavoro L'avatar di cavicchiandrea
    Registrato dal
    Aug 2001
    Messaggi
    26,131
    rendile globali
    codice:
    var lat=0;
    var long=0;
    function check_city()
    {
    
    var place =  $("#city").val();
    geocoder = new GClientGeocoder();
    geocoder.getLatLng(place, function(point) {
        if (!point) {
    
            alert("Place not found. Retry!");
    		$("#city").val("");
    		$('#city').focus(); 	}
            
    	else {
    		lat = point.y;//qui valorizzi latitudine
    		long = point.x;//qui valorizzi longitudine
      }
    });
    }
    Cavicchi Andrea
    Problemi con javascript, jquery, ajax clicca qui

  3. #3
    Utente di HTML.it
    Registrato dal
    Jan 2012
    Messaggi
    154
    Grazie mille
    Mess with the best die like the rest.

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.