Ich habe versucht, Google-Map zu meinem AngularJS Projekt von diesem LinkGoogle-Karte zeigt nicht bei Verwendung von ui-Router
und es funktioniert gut, ohne Zustand (ui-Router) anzuwenden, aber wenn ich versuchte, es zu setzen in mein Projekt, das mehrere Staaten hat, Karte zeigt nicht, aber ... es für einen Ort und Länge erhalten sucht, Breite, wie Sie im Bild
Hier ist ein Teil meines Code
sehenService: app.js
myApp.service('Map', function($q) {
this.init = function() {
var options = {
center: new google.maps.LatLng(40.7127837, -74.00594130000002),
zoom: 13,
disableDefaultUI: true
}
this.map = new google.maps.Map(
document.getElementById("map"), options
);
this.places = new google.maps.places.PlacesService(this.map);
}
this.search = function(str) {
var d = $q.defer();
this.places.textSearch({query: str}, function(results, status) {
if (status == 'OK') {
d.resolve(results[0]);
}
else d.reject(status);
});
return d.promise;
}
this.addMarker = function(res) {
if(this.marker) this.marker.setMap(null);
this.marker = new google.maps.Marker({
map: this.map,
position: res.geometry.location,
animation: google.maps.Animation.DROP
});
this.map.setCenter(res.geometry.location);
}
});
Controller: app.js
myApp.controller('VenueController', function(Map,$rootScope, $scope, $auth, $state, $http) {
Map.init();
$scope.place = {};
$scope.search = function() {
$scope.apiError = false;
Map.search($scope.searchPlace)
.then(
function(res) { // success
Map.addMarker(res);
$scope.place.name = res.name;
$scope.place.lat = res.geometry.location.lat();
$scope.place.lng = res.geometry.location.lng();
},
function(status) { // error
$scope.apiError = true;
$scope.apiStatus = status;
}
);
}
});
HTML
: venue.html
<div style="margin-top:20px;">
<label> Location : </label>
<form name="searchForm" novalidate ng-submit="search()">
<div class="input-group">
<input name="place" type="text" class="form-control"
ng-model="searchPlace" required autofocus />
<span class="input-group-btn">
<button class="btn btn-primary"
ng-disabled="searchForm.$invalid">Search</button>
</span>
</div>
</form>
<div id="map"></div>
<form name="resForm" class="form-horizontal" novalidate
ng-submit="send()">
<div class="form-group">
<label for="resName" class="col-xs-2 control-label">Name</label>
<div class="col-xs-10">
<input name="resName" type="text" class="form-control"
ng-model="place.name" required />
</div>
</div>
<div class="form-group">
<label for="resLat" class="col-xs-2 control-label">Latitude</label>
<div class="col-xs-10">
<input name="resLat" type="number" class="form-control"
ng-model="place.lat" required />
</div>
</div>
<div class="form-group">
<label for="resLng" class="col-xs-2 control-label">Longitude</label>
<div class="col-xs-10">
<input name="resLng" type="number" class="form-control"
ng-model="place.lng" required />
</div>
</div>
Sorry, wenn der Code, den ich Ihnen zeigen, schwierig ist
Bitte helfen Sie, Dank zu lesen im voraus
Können Sie Ihren Code in plunkr ?? –