Skip to content

Commit 03d31b3

Browse files
committed
feat: add code
1 parent 93d5e96 commit 03d31b3

File tree

4 files changed

+117
-2
lines changed

4 files changed

+117
-2
lines changed

README.md

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,41 @@
1-
# geo-coder-umbraco
2-
Geo coding plugin for Umbraco
1+
# Geo-Coder-Umbraco
2+
Geo coding plugin for Umbraco. Feel free to fork and contribute.
3+
4+
# Contributors
5+
6+
[agneysh](https://github.com/agneysh)
7+
8+
9+
# Installation
10+
11+
Download / Clone the project and put it inside a folder under
12+
13+
App_Plugins
14+
15+
geoCoder ( create the folder )
16+
17+
(then you have the files here)
18+
19+
# Technical Details
20+
21+
The GeoCoder will use the address given on the text field and generate coordinates from it.
22+
23+
**Note:**
24+
**Add your google api key on the line 7: "assetsService.loadJs("https://maps.googleapis.com/maps/api/js?key="); "**
25+
26+
27+
28+
Tested up to: Umbraco 7.2
29+
30+
31+
# Commit Messages
32+
Must be one of the following
33+
34+
* build: Changes that affect the build system or external dependencies (example scopes: webpack, npm)
35+
* config: configuration changes only
36+
* docs: Documentation only changes
37+
* feat: A new feature
38+
* fix: A bug fix
39+
* perf: A code change that improves performance
40+
* refactor: A code change that neither fixes a bug nor adds a feature
41+
* style: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)

googlemapgeocoder.controller.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
angular.module("umbraco").controller("googlemapgeocoder.controller",
2+
function ($scope, assetsService) {
3+
// initialise variables
4+
var geocoder;
5+
6+
// use assests service to load Google maps api
7+
assetsService.loadJs("https://maps.googleapis.com/maps/api/js?key=");
8+
9+
// called when Google maps api has loaded
10+
function initialize() {
11+
// create geocoder
12+
geocoder = new google.maps.Geocoder();
13+
14+
}
15+
16+
// runs when geocode button in view is clicked
17+
$scope.codeAddress = function () {
18+
var address = $scope.model.value.address;
19+
20+
var lat, lng;
21+
// use Google api to geocode location
22+
23+
initialize();
24+
geocoder.geocode({ 'address': address }, function (results, status) {
25+
// set location if geocode successful
26+
lat = results[0].geometry.location.lat();
27+
lng = results[0].geometry.location.lng();
28+
$('#clicker').click();
29+
30+
if (status == google.maps.GeocoderStatus.OK) {
31+
// set something to $scope.model.value here.
32+
33+
$scope.model.value.lat = lat;
34+
$scope.model.value.lng = lng;
35+
console.log($scope.model)
36+
var unsubscribe = $scope.$on("formSubmitting", function (ev, args) {
37+
$scope.model.value = { 'address': address, 'lat':lat, 'lng':lng};
38+
//$scope.model.latitude = lat;
39+
//$scope.model.longitude = lng;
40+
});
41+
42+
} else {
43+
alert('Geocode was not successful');
44+
45+
}
46+
});
47+
}
48+
});

googlemapgeocoder.html

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<div ng-controller="googlemapgeocoder.controller">
2+
<input ng-model="model.value.address" type="textbox">
3+
<input type="button" value="Generate Coordinates" ng-click="codeAddress()">
4+
5+
<input disabled="true" ng-model="model.value.lat" type="textbox">
6+
7+
<input disabled="true" ng-model="model.value.lng" type="textbox">
8+
<!--<div>
9+
</div>
10+
<div style="height: 400px;" id="map_canvas"></div>-->
11+
<div id="clicker"></div>
12+
</div>

package.manifest

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
javascript: [
3+
"~/App_Plugins/Geocoder/googlemapgeocoder.controller.js"
4+
],
5+
propertyEditors: [
6+
{
7+
alias: "Geocoder",
8+
name: "Geocoder",
9+
editor:
10+
{
11+
view: "~/App_Plugins/Geocoder/googlemapgeocoder.html",
12+
valueType: "JSON"
13+
}
14+
}
15+
]
16+
}

0 commit comments

Comments
 (0)