【发布时间】:2019-06-24 08:49:36
【问题描述】:
我有一个应用程序,我想展示美国各地即将举行的博览会。我最初被指向 Places API 的方向,然后我被指向 Geocoding API。到目前为止,没有任何效果。代表这么多不同的来源,我的代码会显得断断续续,并试图将事物组合在一起以使其工作。
我正在使用 SQL Server 数据库,并且我有一个包含 ExpoLocations 的表,我有地址、城市、州和邮政编码的字段。我正在尝试使用 c# 创建一个 javascript 数组以插入我的 API。我没有收到任何控制台错误。在我的 Inspector 中,当我查看源代码时,它会返回数组中我需要的项目。我的页面上根本没有显示的地图。
所有代码都在我的视图中
div> id=mapAPI
// #region MAP API
var expos = [];
@foreach (var item in Model.ToList())
{
@:var request = { types: 'street_address', formatted_address: '@item.Address' + '@item.City' + ',' + '@item.State', address_components:{types: 'street_address'}, partial_match: true}
@:expos.push(request);
}
var geocoder;
var map;
function initialize() {
geocoder = new google.maps.Geocoder();
var latlng = new google.maps.LatLng(37.09024, -95.712891);
var mapOptions = {
zoom: 4,
center: latlng
}
map = new google.maps.Map(document.getElementById('mapAPI'), mapOptions);
}
function codeAddress() {
var address = document.getElementById('address').value;
geocoder.geocode( { 'address': address}, function(request, status) {
if (status == 'OK') {
map.setCenter(results[0].geometry.location);
var marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location
});
} else {
alert('Geocode was not successful for the following reason: ' + status);
}
});
}
// #endregion
我在我的脚本中使用这个 API
https://maps.googleapis.com/maps/api/js?key=MYAPIKEY【问题讨论】:
标签: javascript c# sql-server google-maps google-maps-api-3