2010-05-24 5 views
6

मैं एक छोटा सा एप्लीकेशन बनाने की कोशिश कर रहा हूं जो शहर को & राज्य और geocodes लेता है जो एक लेट/लम्बे स्थान पर संबोधित करते हैं। अभी मैं Google Map's API, ColdFusion, और SQL सर्वर का उपयोग कर रहा हूं। असल में शहर और राज्य के क्षेत्र डेटाबेस तालिका में हैं और मैं उन स्थानों को लेना चाहता हूं और Google मानचित्र पर मार्कर डालना चाहता हूं, जहां वे हैं।SQL सर्वर से Google मानचित्र में शहर/राज्य लोड हो रहा है?

यह मेरा कोड है जो geocoding करने के लिए है, और पृष्ठ के स्रोत को देखने से पता चलता है कि यह सही ढंग से मेरी क्वेरी के माध्यम से लूपिंग कर रहा है और पता फ़ील्ड में एक स्थान ("ओमाहा, एनई") रख रहा है, लेकिन कोई मार्कर नहीं है, या कोई मार्कर नहीं है,

var geocoder; 
var map; 

function initialize() { 
    geocoder = new google.maps.Geocoder(); 
    var latlng = new google.maps.LatLng(42.4167,-90.4290); 
    var myOptions = { 
     zoom: 5, 
     center: latlng, 
     mapTypeId: google.maps.MapTypeId.ROADMAP 
    } 
    var marker = new google.maps.Marker({ 
      position: latlng, 
      map: map, 
      title: "Test" 
     }); 
    map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); 
} 

मैं अक्षांश/देशांतर कि मुश्किल था का उपयोग करता है एक नक्शे के काम करने की क्या ज़रूरत है: मानचित्र आरंभ करने के लिए कोड

function codeAddress() { 
<cfloop query="GetLocations"> 
    var address = document.getElementById(<cfoutput>#Trim(hometown)#,#Trim(state)#</cfoutput>).value; 
     if (geocoder) { 
     geocoder.geocode({<cfoutput>#Trim(hometown)#,#Trim(state)#</cfoutput>: address}, function(results, status) { 
     if (status == google.maps.GeocoderStatus.OK) { 
      var marker = new google.maps.Marker({ 
      map: map, 
      position: results[0].geometry.location, 
      title: <cfoutput>#Trim(hometown)#,#Trim(state)#</cfoutput> 
      }); 
     } else { 
      alert("Geocode was not successful for the following reason: " + status); 
      } 
     }); 
     }  
</cfloop> } 

और यहाँ है: उस बात के लिए नक्शा, पृष्ठ पर दिखाया जा रहा है डेटाबेस तालिका में कोडित, लेकिन मैं सिर्फ शहर/राज्य का उपयोग करने और इसे परिवर्तित करने में सक्षम होना चाहता हूं एक लेट/लांग के लिए। कोई सुझाव या दिशा? डेटाबेस में अक्षांश/लंबे समय तक संग्रहीत करना भी संभव है, लेकिन मुझे नहीं पता कि SQL के भीतर ऐसा कैसे करें।

उत्तर

4

आप सह कर सकते हैं

V2 API का उपयोग करना:: निम्न उदाहरण nsider का उपयोग

<!DOCTYPE html> 
<html> 
<head> 
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"/> 
    <title>Google Maps API Geocoding Demo</title> 
    <script src="http://maps.google.com/maps?file=api&amp;v=2&amp;sensor=false" 
      type="text/javascript"></script> 
</head> 
<body onunload="GUnload()"> 

    <div id="map_canvas" style="width: 400px; height: 300px"></div> 

    <script type="text/javascript"> 

    // Prepare this list from ColdFusion 
    var locations = [ 
     'New York, NY', 
     'Los Angeles, CA', 
     'Chicago, IL', 
     'Houston, TX', 
     'Phoenix, AZ' 
    ]; 

    if (GBrowserIsCompatible()) { 
     var map = new GMap2(document.getElementById("map_canvas")); 

     var geocoder = new GClientGeocoder(); 
     var index = 0; 

     var geocoderFunction = function() { 
      geocoder.getLatLng(locations[index], function (point) {  
      if (point) { 
       map.addOverlay(new GMarker(point));     
      } 

      // Call the geocoder with a 100ms delay 
      index++; 
      if (locations.length > index) { 
       setTimeout(geocoderFunction, 100); 
      } 
      }); 
     } 

     map.setCenter(new GLatLng(38.00, -100.00), 3); 

     // Launch the geocoding process 
     geocoderFunction(); 
    } 
    </script> 
</body> 
</html> 

V3 API:

<!DOCTYPE html> 
<html> 
<head> 
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"/> 
    <title>Google Maps API Geocoding Demo</title> 
    <script src="http://maps.google.com/maps/api/js?sensor=false" 
      type="text/javascript"></script> 
</head> 
<body> 

    <div id="map_canvas" style="width: 400px; height: 300px"></div> 

    <script type="text/javascript"> 

    // Prepare this list from ColdFusion 
    var locations = [ 
     'New York, NY', 
     'Los Angeles, CA', 
     'Chicago, IL', 
     'Houston, TX', 
     'Phoenix, AZ' 
    ]; 

    var mapOpt = { 
     mapTypeId: google.maps.MapTypeId.TERRAIN, 
     center: new google.maps.LatLng(38.00, -100.00), 
     zoom: 3 
    }; 

    var map = new google.maps.Map(document.getElementById("map_canvas"), mapOpt); 

    var geocoder = new google.maps.Geocoder(); 
    var index = 0; 

    var geocoderFunction = function() { 
     geocoder.geocode({ 'address': locations[index] }, function (results, status) { 
      if (status == google.maps.GeocoderStatus.OK) { 
      new google.maps.Marker({ 
       map: map, 
       position: results[0].geometry.location 
      });    
      } 

      // Call the geocoder with a 100ms delay 
      index++; 
      if (locations.length > index) { 
      setTimeout(geocoderFunction, 100); 
      } 
     }); 
    } 

    // Launch the geocoding process 
    geocoderFunction(); 
    </script> 
</body> 
</html> 

तुम सब करने की ज़रूरत है उपयोग करने के बजाए, ColdFusion से JavaScript श्रृंखला locations प्रस्तुत करना है उदाहरण में हार्डकोडेड। ऊपर के उदाहरण से

स्क्रीनशॉट:

Google Maps API Geocoding Demo

+0

आपको बहुत बहुत धन्यवाद डैनियल, जैसा कि आप ने कहा कि मैंने किया था और स्थानों चर और यह उत्पादन के अंदर एक सरणी के लिए अपनी क्वेरी बदल दिया। एक जादू की तरह काम किया! – knawlejj

+0

@knawlejj: यह अच्छी खबर है। मुझे खुशी है कि यह काम किया :) –

2

आप वास्तव में addOverlay पद्धति का उपयोग करके नक्शा करने के लिए मार्कर जोड़ने की जरूरत:

var point = new GLatLng(...); 
map.addOverlay(new GMarker(point)); 

तुम भी अपने मानचित्र पर मार्कर वर्ग के उदाहरण जोड़ सकते हैं:

map.addOverlay(marker); 

मानचित्र ओवरले देखें डॉक्स:

http://code.google.com/apis/maps/documentation/javascript/v2/overlays.html

संबंधित मुद्दे