我在嘗試修改Shawn Mayzes JQuery Google Maps插件以支持檢索「當前」latlng屬性。
肖恩的插件和例子可以在這裏找到:http://www.mayzes.org/googlemaps.jquery.examples.html
上我聚焦的例子是「地圖地理編碼簡單」(http://www.mayzes.org/fragments/new/geocode.html)。插件中的相關功能是:
if (opts.geocode) {
geocoder = new GClientGeocoder();
geocoder.getLatLng(opts.geocode, function(center) {
if (!center) {
alert(address + " not found");
}
else {
$.googleMaps.gMap.setCenter(center, opts.depth);
$.googleMaps.latitude = center.x;
$.googleMaps.longitude = center.y;
}
});
}
else {
// Latitude & Longitude Center Point
var center = $.googleMaps.mapLatLong(opts.latitude, opts.longitude);
// Set the center of the Map with the new Center Point and Depth
$.googleMaps.gMap.setCenter(center, opts.depth);
}
現在,我要做的是找回了「中心點」,中心點的緯度/長值,通過廣告地址插件後。
所以,在我的代碼時,我傳遞一個地址,這樣的:
$('#map').googleMaps({
geocode: add
});
我想了一些手段獲取的緯度/長這樣的:
$('#map').getLatLng();
...或作爲插件實例化中的回調函數(就像他們在JQuery UI Tabs控件中那樣)。
這些將是「理想」的解決方案,但在此期間,我願意「的內容自己」有黑客。爲什麼不使用這樣的Jquery「數據」函數?
if (opts.geocode) {
geocoder = new GClientGeocoder();
geocoder.getLatLng(opts.geocode, function(center) {
if (!center) {
alert(address + " not found");
}
else {
alert('center--'+center);
**$(this).data('latlng', center);**
$.googleMaps.gMap.setCenter(center, opts.depth);
$.googleMaps.latitude = center.x;
$.googleMaps.longitude = center.y;
}
});
}
else {
// Latitude & Longitude Center Point
var center = $.googleMaps.mapLatLong(opts.latitude, opts.longitude);
// Set the center of the Map with the new Center Point and Depth
$.googleMaps.gMap.setCenter(center, opts.depth);
}
然後,我將能夠獲取經緯度值,通過簡單地參照:
$('#map').data('latlng');
但是,唉,這並不在所有的工作。
對類似問題的任何指導/提示/解決方案都會有很大的幫助。
無恥
///////////////////////////////////////// ////////////// 對Matchu //////////////////////////////的回覆//////////////////////////
謝謝你的想法。這裏是我的嘗試:
$.googleMaps = {
mapsConfiguration: function(opts) {
var ThisMap = this;
// GEOCODE
if (opts.geocode) {
geocoder = new GClientGeocoder();
geocoder.getLatLng(opts.geocode, function(center) {
if (!center) {
alert(address + " not found");
}
else {
alert('center--'+center);
ThisMap.data('latlng', center);
$.googleMaps.gMap.setCenter(center, opts.depth);...
的「VAR ThisMap =這」是對插件的3號線,這似乎很「高處」給我:)
我嘗試找回「經緯度「使用:
var map = $('#map').googleMaps({
geocode: add
});
alert('latlng--'+map.data('latlng'));
我知道什麼需要在這裏發生可能是因爲我曾經用過類似的使用pattersn與其他插件。不幸的是,這些插件看起來非常「先進」,我還沒有看到在任何簡單的JQuery插件教程中存儲和檢索當前屬性值的示例。有其他人嗎?
試圖通過鍵訪問數據如下: \t變種地圖= $( '#地圖')GOOGLEMAPS({ \t \t地理編碼:添加 \t}); alert('latlng - '+ map.data('latlng')); ...並且這也不起作用。 – shamelesshacker 2010-01-14 00:57:42