Mobile Report JS Development Example-Get location

Source: Internet
Author: User

The last time I shared the Mobile Report JS development system concept, and then I went back to explore a number of cases. Previously contacted by the Finereport app client can be used to punch in the check-in, Curiosity studied the following, this time to talk about the report mobile development How to achieve the positioning function.

1. Solution Ideas

When you design a template with Finereport, add a button control, click the button, get the current location, and copy the location information to a cell, and finally the client to fill out the current template.

2. Example

To achieve the effect shown, click the Location button to get the current position and current time, and display it in the corresponding cell below:

2.1 Template Making

Open the designer, create a new template, design the template as shown in, where E2 is a button control, the control name is a geographic location, C5 is a drop-down box control, E5 is a Time control:

2.2 Get Current Location

There are two ways to get the current location, one is to click the button to get a location, one is to open the template directly when the location is obtained, in the example, we want to achieve by clicking the button to obtain the geographical location.

Get a location by clicking the button

Open the control settings for the button and add a click event for the control, such as

JS as follows:

// Get a location if (status== "Success") {// positioning succeeds, message returns latitude and longitude value 4. FR. Msg.alert ("Current position is" + message); 5. Contentpane.setcellvalue (2, 3, message); Else {// location failed, message returned corresponding error message // location failed 9.} 10

Click (here) to collapse or open

Finereport gets the current position through the Fr.location method, or if the status value is success, it means that the location is successful or the location fails, and if the location is successful, the returned geo-location information is assigned to the C4 cell.

However, this method is only useful on the mobile side, if you click on the button event in the Web to obtain a geographic location, the direct prompt to locate failed.

Get the current location after loading ends

If you want to get to the current location after the template is loaded, simply add the above code to the post-load event, open the template, click Templates > Templates Web properties > Fill in the page settings, add a load end event such as:

2.3 Get current Time

The current check-in time in the template also needs to be assigned to the past, so you also need to get the current time in the button's click event, and assign the value to E4 cell, JS as follows:

New Date (); // gets the current time of 13. Contentpane.setcellvalue (4, 3, mytime);

button click event All JS as follows:

Fr.location (function (status, message) {//Get a location15.if(status== "Success") {16.//position successful, message returns latitude and longitude value. FR. Msg.alert ("Current position is" +message);Contentpane.setcellvalue (2, 3, message);var mydate =NewDate ();var mytime=mydate.getfullyear () + "-" +mydate.getmonth () +1+ "-" +mydate.getdate () + "" +mydate.gethours () + ":" + Mydate.getminutes () + ":" +mydate.getseconds ();//Get current TimeContentpane.setcellvalue (4, 3, mytime);22.23.}Else {24.//failed to locate, message returns the corresponding error message. FR. Msg.alert (message);//failed to locate26. }27.});


2.4 Effect View

Add the template to the tree of nodes in your data decision system, and how to do this by looking at the Add template, where the template is previewed, such as:

Based on the steps described in adding a server section, log in to the system with the mobile side, access the template, click the Location button to get the current location and current time, such as:

However, the geographic location acquired by Finereport is longitude and latitude, and if you need to determine its exact location, you will need to convert it separately.

Mobile development is also ongoing learning, interested friends can join me to explore the study.

Mobile Report JS Development Example-Get location

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.