Get Location (Latitude and Longitude) using Google Maps API in AngularJS

Last Reply 3 months ago By skp

Posted 3 months ago

How to simply get the latitude, longitude and location in angularjs?


Posted 3 months ago

Hi skp,

Using the below articles i have created the example. 

Check this example. Now please take its reference and correct your code.

Get Current Location Latitude and Longitude using JavaScript and HTML5

Google Maps V3: Get address from Latitude and Longitude


<html xmlns="">
    <script type="text/javascript" src=""></script>
    <script type="text/javascript" src=""></script>
    <script type="text/javascript">
        var app = angular.module('MyApp', []);
        app.controller('MyController', function () {
            if (navigator.geolocation) {
                navigator.geolocation.getCurrentPosition(function (p) {
                    var latlng = new google.maps.LatLng(p.coords.latitude, p.coords.longitude);
                    var geocoder = geocoder = new google.maps.Geocoder();
                    geocoder.geocode({ 'latLng': latlng }, function (results, status) {
                        if (status == google.maps.GeocoderStatus.OK) {
                            if (results[1]) {
                                "Location: " + results[1].formatted_address +
                                "\nLatitude : " + p.coords.latitude +
                                "\nLongitude : " + p.coords.longitude);
            } else {
                alert('Geo Location feature is not supported in this browser.');
<body ng-app="MyApp" ng-controller="MyController">


Posted 3 months ago

I guess the geolocation doesn't support in http site, but it supports localhost site.

Only when it comes to https site, it supports.