JAVASCRIPT
What
is Javascript?
Javascript is a
Scripting Language and Programming Language JavaScript was introduced in 1995.it’s execute within a browser ,Javascript code is embed in HTML webpage. <script>
tag is used to javascript code.
Different
type Javascript code embedded in
Using head tag
Using Body tag
Using External script
Head Tag Embed in:
<html>
<head>
<script type=”text/javascript”></script>
</head>
<body>
</body>
</html>
External
Script:
<html>
<head>
<script src=”external.js”></script>
</head>
<body>
</body>
</html>
Body Tag Embed in:
<html>
<head>
</head>
<body>
<script type=”text/javascript”></script>
</body>
</html>
Javascript
Function:
Function is a keyword name of Function . set open and
close Parantheses enclose with parameter
and without parameter and the curly braces
<html>
<head>
<script>
function sum(a,b)
{
return a*b;
}
</script>
</head>
<body>
<script>
document.writeln(sum(10,10));
</script>
</body>
</html>
JAVASCRIPT ELEMENTS
Ø Variables
Ø Objects
Ø Operators
Ø Statements
Ø Function and Methods
Variables:
Variable is also called Identifier. Variables are Containers for Storing Data or Information.
Rules for Variables
Starting first letter or Underscore Character
Do not use Numbers
Javascript is a Casesensitive
Variable is a assigned with = operator
Scope of Variables:
Ø Local
Ø Global
Local:
A variables is declared inside a method is called local variables. Only access within function
Ex:
<html>
<head>
<title> sum </title>
<title> sum </title>
<script>
function sum(){
var a=10;
var b=20;
var c=a+b;
alert(c);
}
</script>
</head>
</html>
Global:
Global variables is access anywhere in the page .once declared global variable
Access with function or without function
Ex:
<html>
<head>
<title> add </title>
<title> add </title>
<script>
Var a,b;
function sum(){
a=10;
b=20;
var c=a+b;
alert(c);
}
</script>
</head>
</html>
DATA TYPES
Numbers => Integer and Floating Points 1 or 1.0
Booleans => Boolean is True or False and 0 0r 1
Strings => String is a Sequence of Character " hello world "
Objects => Represent elements of html page
Null => No values is assigned or empty values
https://developer.here.com
);
JAVASCRIPT USING GET CURRENT LOCATION
d Reffer This Site To get API key:
https://developer.here.com
Then Go to This Site Create Account and Login , And this website gave a API and Code to use
Example
<script src="https://js.api.here.com/v3/3.0/mapsjs-core.js" type="text/javascript" charset="utf-8"></script>
<script src="https://js.api.here.com/v3/3.0/mapsjs-service.js" type="text/javascript" charset="utf-8"></script>
<script>
var platform = new H.service.Platform({
"app_id": "Your APP ID",
"app_code": "Your APP Code"
});
var geocoder = platform.getGeocodingService();
if(navigator.geolocation) {
navigator.geolocation.getCurrentPosition(position => {
geocoder.reverseGeocode(
{
mode: "retrieveAddresses",
maxresults: 1,
prox: position.coords.latitude + "," + position.coords.longitude
}, data => {
var cty=data.Response.View[0].Result[0].Location.Address.City;
window.location.href='https://localhost/demo/index.php?city='+btoa(cty);
}, error => {
console.error(error);
}
);
},err =>{
let e=err.code;
if(e==1){
;
Swal.fire({
title: 'You Denied The Location',
text: 'Allow the Location',
type: 'error',
confirmButtonText: 'Allow'
}).then((e)=>{
alert('denied location');
});
if(navigator.geolocation){
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition);
} else {
navigator.geolocation.getCurrentPosition(showPosition);
}
}
})
);
} else {
console.error("Geolocation is not supported by this browser!");
}
</script>
No comments:
Post a Comment