Draw Route Between Two Locations Using MapKit in Swift

Vrundesha Joshi
Updated on 30-Jul-2019 22:30:24

935 Views

To draw a route between two Locations on map we need to have co-ordinates of both those locations.Once we have the co-ordinates of both locations we can use the below given function to show the line between two points on map. In this example I’ll be using two random location as two points.func getDirections(loc1: CLLocationCoordinate2D, loc2: CLLocationCoordinate2D) {    let source = MKMapItem(placemark: MKPlacemark(coordinate: loc1))    source.name = "Your Location"    let destination = MKMapItem(placemark: MKPlacemark(coordinate: loc2))    destination.name = "Destination"    MKMapItem.openMaps(with: [source, destination], launchOptions: [MKLaunchOptionsDirectionsModeKey: MKLaunchOptionsDirectionsModeDriving]) }We’ll call this function in ViewDidLoad for this tutorial to show the ... Read More

Find All Words That Start with 'A' in Java

Rishi Raj
Updated on 30-Jul-2019 22:30:24

651 Views

All the words that start with a can be found in a string by using regular expressions in Java. The regular expressions are character sequences that can be used to match other strings using a specific pattern syntax. The regular expressions are available in the java.util.regex package which has many classes but the most important are Pattern class and Matcher class.A program that finds all words that start with an 'a' is using regular expressions is given as follows:Example Live Demoimport java.util.regex.Matcher; import java.util.regex.Pattern; public class Demo {    public static void main(String args[]) throws Exception {       String ... Read More

Sort Varchar Column as Float Using CAST Operator in MySQL

Arjun Thakur
Updated on 30-Jul-2019 22:30:24

1K+ Views

If your cast does not work, then you can use yourColumnName*1 with ORDER BY clause.Using yourColumnName*1. The syntax is as follows:SELECT yourColumnName1, yourColumnName2, ...N FROM yourTableName ORDER BY yourColumnName*1 DESC;You can also use CAST() operator. The syntax is as follows:SELECT yourColumnName1, yourColumnName2, ...N FROM yourTableName ORDER BY CAST(yourColumnName as DECIMAL(8, 2)) DESC;To understand the above syntax, let us create a table. The query to create a table is as follows:mysql> create table VarcharColumnAsFloatDemo -> ( -> Id int NOT NULL AUTO_INCREMENT, -> Amount varchar(20), -> PRIMARY KEY(Id) ... Read More

DecimalFormat in Java

karthikeya Boyini
Updated on 30-Jul-2019 22:30:24

140 Views

DecimalFormat is a concrete subclass of NumberFormat that formats decimal numbers. Let us set DecimalFormat("###E0") and use the format() method as well.DecimalFormat decFormat = new DecimalFormat("##E0"); System.out.println(decFormat.format(-267.9965)); System.out.println(decFormat.format(8.19)); System.out.println(decFormat.format(9897.88));Since we have used DecimalFormat class in Java, therefore importing the following package is a must −import java.text.DecimalFormat;The following is the complete example −Example Live Demoimport java.text.DecimalFormat; public class Demo { public static void main(String[] argv) throws Exception { DecimalFormat decFormat = new DecimalFormat("###E0"); System.out.println(decFormat.format(-267.9965)); System.out.println(decFormat.format(8.19)); ... Read More

Format Java Date to String using SimpleDateFormat e DD MMM YYYY HH MM SS Z

karthikeya Boyini
Updated on 30-Jul-2019 22:30:24

5K+ Views

Using the SimpleDateFormat(“E, dd MMM yyyy HH:mm:ss Z”), wherein E is for Day of Week −// displaying current date and time Calendar cal = Calendar.getInstance(); SimpleDateFormat simpleformat = new SimpleDateFormat("E, dd MMM yyyy HH:mm:ss Z"); System.out.println("Today's date and time = "+simpleformat.format(cal.getTime()));Since we have used the Format and SimpleDateFormat class above, therefore import the following packages. With that, we have also used the Date −import java.text.Format; import java.text.SimpleDateFormat; import java.util.Date;The following is an example −Example Live Demoimport java.text.Format; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Calendar; public class Demo { public static void main(String[] args) throws Exception { ... Read More

Order Strings by Length of Characters in MySQL

Vrundesha Joshi
Updated on 30-Jul-2019 22:30:24

427 Views

You can order by length of characters with the help of CHAR_LENGTH() function from MySQL. The function returns the number of characters i.e. 4 for the following string −AMITTo order strings by length of characters, the following is the syntax −select *from yourTableName order by CHAR_LENGTH(yourColumnName);To understand the above concept, let us first create a table. The following is the query to create a table −mysql> create table OrderByCharacterLength    −> (    −> BookName varchar(200)    −> ); Query OK, 0 rows affected (1.97 sec)Insert some records in the table with the help of insert command. The query is ... Read More

Greedy Qualifier in Java Regular Expressions

Fendadis John
Updated on 30-Jul-2019 22:30:24

233 Views

A greedy qualifier repeats the specified token as many times as possible and then the engine backtracks and the greedy qualifier gives up matches to eventually find the required match.The regex "(\w+)(\d)(\w+)" is used to find the match in the string "EarthHas1Moon".A program that demonstrates this is given as follows:Example Live Demoimport java.util.regex.Matcher; import java.util.regex.Pattern; public class Demo {    public static void main(String args[]) {       String str = "EarthHas1Moon";       String regex = "(\w+)(\d)(\w+)";       Pattern p = Pattern.compile(regex);       Matcher m = p.matcher(str);       m.find();       ... Read More

Get Column Name from ResultSet in Java with MySQL

Samual Sam
Updated on 30-Jul-2019 22:30:24

734 Views

To get the column name on the result set, you need to use getMetaData() method. The prototype of getMetadata() is as follows −ResultSetMetaData getMetaData throws SQLException;Create a MySQL table with 5 column names. The query to create a table is as follows −mysql> create table javagetallcolumnnames    -> (    -> Id int NOT NULL AUTO_INCREMENT,    -> Name varchar(20),    -> Age int,    -> Salary float,    -> Address varchar(100),    -> PRIMARY KEY(Id)    -> ); Query OK, 0 rows affected (1.34 sec)The following is the Java code that gets the column name on ResultSet. The code ... Read More

Round Number to Fewer Decimals in Java

Samual Sam
Updated on 30-Jul-2019 22:30:24

161 Views

Let’s say we need to round number to 3 decimal places, therefore use the following format −DecimalFormat decFormat = new DecimalFormat("0.000");Now, format the number −decFormat.format(37878.8989)Since we have used the DecimalFloat class above, therefore do import the following package −import java.text.DecimalFormat;The following is an example that rounds a number to 3 decimal places −Example Live Demoimport java.text.DecimalFormat; public class Demo {    public static void main(String[] args) {       DecimalFormat decFormat = new DecimalFormat("0.000"); System.out.println("Result = " + decFormat.format(37878.8989)); } }OutputResult = 37878.899Let us see another example that rounds a number ... Read More

Display Year with SimpleDateFormat yyyy in Java

Samual Sam
Updated on 30-Jul-2019 22:30:24

574 Views

Using the SimpleDateFormat(“yyyy”) to display year −// displaying year Format f = new SimpleDateFormat("yyyy"); String strYear = f.format(new Date()); System.out.println("Year = "+strYear);Since, we have used the Format and SimpleDateFormat class above, therefore import the following packages. With that, we have also used the Date −import java.text.Format; import java.text.SimpleDateFormat; import java.util.Date;The following is an example −Example Live Demoimport java.text.Format; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Calendar; public class Demo {    public static void main(String[] args) throws Exception {       // displaying current date and time       Calendar cal = Calendar.getInstance();       SimpleDateFormat simpleformat = new SimpleDateFormat("E, ... Read More

Advertisements