English 中文(简体)
使用地理编码的 init gmap3
原标题:init gmap3 using geocode

I am new to gmap3, is it possible to init the gmap3 using a place address? I know generally it is done with latitude and longitude. I have done markers with this this location name using this example. I have already gone through this example too, but no luck. And also i need to zoom the places on selection, i use auto complete for this purpose.

我的代码如下:

 $( #test ).gmap3(
     { action: init ,
         options:{
             address: "kerala,india"
         }
     }

 );
最佳回答

首先使用 getLatLng () 来检索位置, 当成功设置中心时 :

   $( #test1 ).gmap3(
    { action :  getLatLng ,
      address: kerala,india ,
      callback : function(result){
        if (result){
          $(this).gmap3({action:  setCenter , args:[ result[0].geometry.location ]},
                        {action:  setZoom , args:[ 12]});
      } else {
      alert( not found ! );
      }}});
问题回答
var add="kerala,india";
var geocoder = new google.maps.Geocoder();

geocoder.geocode({ address: add, region:  no  },
function (results, status) {
 if (status.toLowerCase() ==  ok ) {
    // Get center
    var coords = new google.maps.LatLng(
        results[0][ geometry ][ location ].lat(),
        results[0][ geometry ][ location ].lng()
    );
    //alert(coords);
    $map.gmap3("get").setCenter(coords);
    $map.gmap3("get").setZoom(12);
    addMarker(coords);
 }
 else {
    alert("address not found");
 }
}    

function addMarker(marker) {
    $map = $( #googleMap );
    if (marker) {
        $map.gmap3(
            { action:  init ,
                options: {
                    center: eval(marker),
                    zoom: 12,
                    mapTypeId: google.maps.MapTypeId.ROADMAP
                }
            },
            { action:  addMarker ,
                latLng: eval(marker),
                options: {
                    draggable: true,
                    icon: new google.maps.MarkerImage( http://maps.google.com/mapfiles/marker.png )
                },
                events: {
                    dragend: function (mark) {
                        updateMarker(mark);
                    }
                }
            });
    }
}

使用上述代码,您还可以获得纬度/纬度,并拖动搜索位置标记。

此特性将在下一个版本( 5. 0) 中出现, 当前没有更新 。

以下是工作守则:

  $( #test1 ).gmap3({ 
    action :  getLatLng ,
    address: kerala,india ,
      callback : function(result){
        if (result){
          $(this).gmap3({
            action: "init",
            options:{
                center: result[0].geometry.location,
                zoom: 12
            } 
        });
      } else {
        alert( not found ! );
      }
    }
});

通知,如果您的地图已经初始化,您可以在回调中使用

    $(this).gmap3("get").setCenter(result[0].geometry.location);
    $(this).gmap3("get").setZoom(12);

您也可使用以下代码:

var markerData = [];
markerData.push({ address:  kerala,india , data:    });
$( #test ).gmap3({
   action:  addMarkers ,
   markers: markerData
   }
);




相关问题
How to decide the current point reach on google map?

How to decide the current point reach on google map? I have a list of points (pickup points) of a route that I want to show in my google map with polyline. Now i have to get the current location of ...

Topographical or relief data in Map APIs

I was wondering if anyone knew of any map APIs that offer topographical or relief data? I ve had a quick look at Google and Bing APIs, but could find nothing there. Google allow you to view a map as ...

Using maps on Windows Mobile

I m experimenting with maps on different mobile platforms. Getting Google Maps to work on Android was easy, following this tutorial. Getting the same to work on Windows Mobile is a different matter. ...

Adding a custom icon to a google map

I need a hand adding a custom icon to some Google Maps javascript. Code below for your reference: function populateMap() { var map = new GMap2(document.getElementById("map")); map.setCenter(new ...

RSS to KML Overlay

I m want to display my blog as a Google Map overlay (each post contains geotags). How can I dynamically create a KML overlay from an RSS? Or better, how can I create a loop (PHP) that would display ...

开放街道地图管理员

我需要开放Street的标记管理员。 地图,如山角地图。

热门标签