2016-11-04 42 views
0

不工作我在reactjs相当新的,科尔多瓦 我附上navigator.geolocation.getCurrentPosition(successFunction,errorFunction);在reactjs

navigator.geolocation.getCurrentPosition(successFunction,errorFunction); 
function successFunction(position) 
{ 
    var lat = position.coords.latitude; 
    var lng = position.coords.longitude; 
    geolocation=lat+" "+lng; 
} 

getContent: function() 
{ 
    var feedbackObj = Store.getData(); 
    if(!feedbackObj) 
    { 
     actions.getFormData(); 
     return(
      <div className="gclass form"> 
      <Loader /> 
      </div> 
     ); 
    } 
    var className = "hide"; 
    if(feedbackObj["receive_update"] === "1") 
    { 
     className = "feedbackUserDetails"; 
    } 

    navigator.geolocation.getCurrentPosition(successFunction1, errorFunction1); 

    function successFunction1(position) 
    { 
     lat = position.coords.latitude; 
     lng = position.coords.longitude; 
     geolocation=lat+" "+lng; 
     console.log(geolocation); 
     console.log("ABC"); 
    } 
    function errorFunction1() 
    { 
     alert("Geocoder failed"); 
    } 
    return(
    <div className="gclass form"> 
    <TextArea name={"incident_title"} isRequired={true} limit={2000} onSave={this._onSave} id={"incident_title"} defaultvalue={feedbackObj["incident_title"]}/> 
    <TextArea name={"incident_desc"} isRequired={true} limit={2000} onSave={this._onSave} id={"incident_desc"} defaultvalue={feedbackObj["incident_desc"]}/> 
    <Calendar name={"incident_date"} isRequired={true} id={"incident_date"} onSave={this._onSave} defaultvalue={feedbackObj["incident_date"]} /> 
    <TextBox name={"incident_location"} isRequired={true} id={"incident_location"} onSave={this._onSave} defaultvalue="abc" /> 
    <Attach name={"upload_attachment"} id={"upload_attachment"} onSave={this._onSave} defaultvalue={feedbackObj["upload_attachment"]} /> 
    </div>   
    ); 
} 

到我的反应JSX文件。但它不叫后盾,我的任何功能(successFunction或误差函数)的

获取内容,这里称为

getInitialState: function() { 
return {content:this.getContent()}; 

}

,我需要补充一些要求呢?

+0

你如何在反应文件中调用这个函数,你能分享一些代码吗? – Sachin

+0

@Sachin我添加了几件东西 –

+0

你是怎么调用getContent的? 请提供与问题相关的所有细节。检查如何提出一个好问题的指导原则。 – Sachin

回答

1

getCurrentPosition()不再适用于Chrome中不安全的起源。要使用此功能,您应该考虑将应用程序切换到安全的来源,例如HTTPS。

+0

,但它应该在其他浏览器上工作,并且我在移动应用程序的cordova中使用了reactjs –