2012-03-05 79 views
3

我正在使用谷歌API來自動完成用戶地址功能。它的工作正常。 但現在我想使用諾基亞OVI地圖進行地址自動完成功能。諾基亞OVI地圖自動完成功能

請幫助我如何實現相同。

我使用下面的代碼

<div id="customSearchBox" class="main-search"> 
     <span class ="caption">Search For Places:</span> 
     <div module="SearchBox"> 
      <input rel="searchbox-input" class="search-box-bckgrnd" type="text" /> 
      <div rel="searchbox-list" class="search-list"></div> 
     </div> 
    </div> 
    <script> 
     var customSearchBox = new nokia.places.widgets.SearchBox({ 
      targetNode: 'customSearchBox', 
      template: 'customSearchBox', 
      searchCenter: function() { 
       return { 
        latitude: 52.516274, 
        longitude: 13.377678 
       } 
      }, 
      onResults: function (data) { 
       //here you have access to data 
       alert(data); 
      } 
     }); 
    </script> 

如何獲得緯度,經度在此代碼

感謝 Shivam

回答

0

我通過閱讀Ovi地圖的文件得到了我的問題的答案。

<script> 
     var customSearchBox = new nokia.places.widgets.SearchBox({ 
      targetNode: 'customSearchBox', 
      template: 'customSearchBox', 
      searchCenter: function() { 
       return { 
        latitude: 52.516274, 
        longitude: 13.377678 
       } 
      }, 
      onResults: function (data) { 
       //here you have access to data 
       //var a=getData(); 
       renderResults(data); 
       //alert(data.results[0]); 
      } 
     }); 

     function renderResults (data) { 
     var previewList = document.getElementById ('results'); 
     previewList.innerHTML = ''; 

     var results = data.results; 

     for (var i = 0, l = results.length; i < l; i++) { 
      var result = results[i]; 
      var resultLi = document.createElement ('li'); 
      resultLi.innerHTML = result.place.name+" - Lat:"+result.place.location.position.latitude+" Long:"+result.place.location.position.longitude; 
      //alert(result.place.location.position.longitude); 
      previewList.appendChild (resultLi); 
     } 
    } 

    </script> 

我希望這會對某人有所幫助。

感謝 Shivam

0

jQuery的你可以用一個文本框像這樣做,因爲我不希望使用預定義的「搜索框控件」:

$('#location_address').autocomplete({ 
    focus:function (event, ui) { 
     return false; 
    }, 
    search:function() { 
     $(this).addClass('working'); 
    }, 
    open:function() { 
     $(this).removeClass('working'); 
    }, 
    select:function (event, ui) { 
     var position = ui.item.id.split(";"); 
     var coord = new nokia.maps.geo.Coordinate(parseFloat(position[0]), parseFloat(position[1])) 

     $('#location_address').val(ui.item.label) 
     $('#location_longitude')[0].value = coord.longitude; 
     $('#location_latitude')[0].value = coord.latitude; 
     map.setCenter(coord, "default"); 
     map.setZoomLevel(16); 
    }, 
    source:function (request, response) { 
     var searchCenter = { 
      latitude:52.516274, 
      longitude:13.377678 
     }; 
     nokia.places.search.manager.findPlaces({ 
      searchTerm:request.term, 
      onComplete:function (data, status) { 

       var nData = data.results.map(function (val, i) { 
        return { 
         value:val.place.name, 
         id:val.place.location.position.latitude + ";" + val.place.location.position.longitude 
        }; 
       }) 
       response(nData); 

      }, 
      searchCenter:searchCenter, 
      didYouMean:5 
     }); 
    }, 
    minLength:2 
});