ယနေ့ဝက်ဘ်ဆိုက်ဖွံ့ဖြိုးတိုးတက်မှုတွင် Geolocation နှင့်မြေပုံ 0 န်ဆောင်မှုများသည် 0 ဘ်ဆိုဒ်များနှင့် applications များစွာ၏အရေးကြီးသောအစိတ်အပိုင်းတစ်ခုဖြစ်လာသည်။ အသုံးပြုသူနေရာများကိုပြသရန် (သို့) နေရာချထားခြင်းဆိုင်ရာလမ်းညွှန်ချက်ကိုအကောင်အထည်ဖော်ရန်ဆိုသည်မှာ PHP Language နှင့် Mainstrents Map API ကို သုံး. ဤကဲ့သို့သောလုပ်ဆောင်မှုကိုပြီးမြောက်စေရန် PHP ဘာသာစကားနှင့်ပင်မမြေပုံ api ကိုသုံးနိုင်သည်။ ဤဆောင်းပါးသည် Google Maps API နှင့် Baidu Maps API နှင့်အတူ Baidu Maps API တို့မှတဆင့်မည်ကဲ့သို့အကောင်အထည်ဖော်ရန်မည်သို့အကောင်အထည်ဖော်ရမည်ကိုအသေးစိတ်ဖော်ပြထားသည်။
Google Maps သည် GEP အမျိုးအစားများကိုအသုံးပြုသူ IP မှဆင်းသက်လာနိုင်သည့် JavaScript နှင့် back-end php ကိုပေါင်းစပ်ပြီး 0 က်ဘ်မြေပုံပေါ်တွင်ပြသနိုင်သည်။ အောက်ဖော်ပြပါသည်၎င်းကိုအကောင်အထည်ဖော်ရန်ဖြစ်သည်။
<?php
// client ကိုရယူပါIPစကားပေြာဟော
$ip = $_SERVER['REMOTE_ADDR'];
// တတိယပါတီကိုသုံးပါAPIတည်နေရာသတင်းအချက်အလက်ကိုရယူပါ
$location = file_get_contents("http://ip-api.com/json/{$ip}");
// သုံးသပ်ကြည့်ရှုခြင်းJSON
$locationData = json_decode($location);
// လတ်တီတွဒ်နှင့်လောင်ဂျီတွဒ်ရယူပါ
$latitude = $locationData->lat;
$longitude = $locationData->lon;
// output ကိုတည်နေရာသတင်းအချက်အလက်
echo "မင်းIPစကားပေြာဟော:{$ip}<br>";
echo "မင်း经纬度:{$latitude}, {$longitude}<br>";
// မြေပုံကွန်တိန်နာကိုပြပါ
echo "<div id='map' style='width:100%; height:400px; margin-top:20px; border:1px solid #ccc;'></div>";
// မိတ်ဆက်ခဲ့သည်Google Maps APIမြေပုံကိုအစပြုပါ
echo "<script src='https://maps.googleapis.com/maps/api/js'></script>";
echo "<script>
function initMap() {
var location = {lat: {$latitude}, lng: {$longitude}};
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 8,
center: location
});
var marker = new google.maps.Marker({
position: location,
map: map
});
}
initMap();
</script>";
?>
အထက်ပါကုဒ်မှတဆင့်အသုံးပြုသူ၏ IP သည်ပထဝီအနေအထားမှအလိုအလျောက်ခွဲခြမ်းစိတ်ဖြာပြီး Google Maps ၏ဗဟိုတွင်ပြသခဲ့သည်။
Baidu Maps သည် IP positioning နှင့်မြေပုံ display function များကိုလည်းတရုတ်နိုင်ငံရှိအသုံးချသူများအတွက်သင့်တော်သော IP display function များကိုလည်းပေးသည်။ အောက်ဖော်ပြပါသည် PHP နှင့် Baidu Maps API ကို အသုံးပြု. လုပ်ငန်းဆောင်တာများကိုအကောင်အထည်ဖော်ရန်နမူနာကုဒ်ဖြစ်သည်။
<?php
// client ကိုရယူပါIP
$ip = $_SERVER['REMOTE_ADDR'];
// Baidu Maps ကိုအသုံးပြုခြင်းAPIတည်နေရာကိုရယူပါ
$location = file_get_contents("http://api.map.baidu.com/location/ip?ak=Your_AK&ip={$ip}&coor=bd09ll");
// သုံးသပ်ကြည့်ရှုခြင်း返回的JSONအချက်များ
$locationData = json_decode($location);
// ထုတ်ယူလတ်တီတွဒ်နှင့်လောင်ဂျီတွဒ်
$latitude = $locationData->content->point->y;
$longitude = $locationData->content->point->x;
// output ကိုတည်နေရာသတင်းအချက်အလက်
echo "မင်းIPစကားပေြာဟော:{$ip}<br>";
echo "မင်း经纬度:{$latitude}, {$longitude}<br>";
// မြေပုံကွန်တိန်နာ
echo "<div id='map' style='width:100%; height:400px; margin-top:20px; border:1px solid #ccc;'></div>";
// Baidu မြေပုံကို load လုပ်ပါ
echo "<script src='http://api.map.baidu.com/api?v=2.0&ak=Your_AK'></script>";
echo "<script>
function initMap() {
var map = new BMap.Map('map');
var point = new BMap.Point({$longitude}, {$latitude});
map.centerAndZoom(point, 12);
var marker = new BMap.Marker(point);
map.addOverlay(marker);
}
initMap();
</script>";
?>
ဤကုဒ်သည်သုံးစွဲသူ၏ IP အပေါ် အခြေခံ. တည်နေရာအချက်အလက်များရရှိရန်အတွက် Baidu Map Interface ကို အသုံးပြု. မြေပုံတွင်မှတ်သားထားသည်။ ၎င်းသည်ဒေသဆိုင်ရာစီမံကိန်းဖွံ့ဖြိုးတိုးတက်မှုအတွက်အလွန်သင့်တော်သည်။
အမှန်တကယ်ကုဒ်နမူနာများမှတဆင့်ဤဆောင်းပါးတွင် Google Maps API ကိုမည်သို့အသုံးပြုရမည်ကို PHP ဘက်မှအကောင်အထည်ဖော်ရန် API ကိုမည်သို့အသုံးပြုရမည်ကိုပြသသည်။ developer များသည်၎င်းတို့၏လိုအပ်ချက်များနှင့်အညီသင့်လျော်သောမြေပုံဝန်ဆောင်မှုပလက်ဖောင်းများကို ရွေးချယ်. အမှန်တကယ်စီမံကိန်းများတွင်ဤအလုပ်လုပ်နိုင်သော module များကိုပိုမိုချဲ့ထွင်နိုင်သည်။