2012-08-25 9 views
6

मैं खुद को एक औसत PHP कोडर मानता हूं, लेकिन मैं अपनी वेबसाइटों पर जावास्क्रिप्ट कोड के कुछ बिट्स को मुश्किल से संपादित कर सकता हूं। मेरे पास एक PHP चर में एक पता है और मैं उस पते के साथ अपने वेबपृष्ठ पर दिखाने के लिए एक साधारण मानचित्र चाहता हूं। मैंने इंटरनेट पर कुछ शोध किया है और मुझे बहुत से ऑप जियोकोडिंग मिलती हैं, जो Google एपीआई को समझने वाले स्थान पर एक पता बदलती है, लेकिन मैं पूरी तरह से खो गया हूं। क्या कोड का कोई आसान टुकड़ा नहीं है जिसमें मैं अपने चर को एम्बेड कर सकता हूं?PHP वैरिएबल में पता, Google मानचित्र जावास्क्रिप्ट के बिना एम्बेडिंग?

+0

चेक इस सवाल से बाहर , यह मदद करनी चाहिए: http://stackoverflow.com/questions/4157750/passing-address-to-google-maps-on-page-load – BenOfTheNorth

उत्तर

21

आप एक आईफ्रेम का उपयोग कर सकते हैं और पते को यूआरएल पैरामीटर के रूप में पास कर सकते हैं।

<iframe width="640" height="480" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="https://maps.google.it/maps?q=<?php echo $yourAddress; ?>&output=embed"></iframe> 
+1

परफेक्ट एन सुपर आसान समाधान, धन्यवाद! – user1555076

+1

आपका स्वागत है! – Napolux

+1

मैंने अभी भी इसका इस्तेमाल किया, एक इलाज किया! – Supplement

3

आप Geocoder API का उपयोग करना होगा।

यहां आपको (मूल पाया जा सकता है here):

<head> 
... 
<script src="https://maps.googleapis.com/maps/api/js?sensor=false"></script> 
<script> 
    var geocoder; 
    var map; 
    function initialize() { 
    geocoder = new google.maps.Geocoder(); 

    var mapOptions = { 
     zoom: 12, //Change the Zoom level to suit your needs 
     mapTypeId: google.maps.MapTypeId.ROADMAP 
    } 
    //map_canvas is just a <div> on the page with the id="map_canvas" 
    map = new google.maps.Map(document.getElementById('map_canvas'), mapOptions); 

    //Your Variable Containing The Address 
    var address = "<?php echo $AddressVariable; ?>"; 
    geocoder.geocode({ 'address': address}, function(results, status) { 
     if (status == google.maps.GeocoderStatus.OK) { 
     map.setCenter(results[0].geometry.location); 
     //places a marker on every location 
     var marker = new google.maps.Marker({ 
      map: map, 
      position: results[0].geometry.location 
     }); 
     } else { 
     alert('Geocode was not successful for the following reason: ' + status); 
     } 
    }); 

    } 

</script> 
... 
</head> 

अपने पृष्ठ के उद्घाटन body टैग में यह जोड़े मानचित्र आरंभ करने के लिए: के लिए

<body onload="initialize()"> 

और here's प्रलेखन Geocoder कक्षा।

0
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script> 
<?php 
$address = str_replace(" ", "+",$address_variable); 
?> 
<iframe style="width:100%;height:50%;" frameborder="0" id="cusmap" scrolling="no" marginheight="0" marginwidth="0" src="https://maps.google.it/maps?q=<?php echo $address; ?>&output=embed"></iframe> 
संबंधित मुद्दे