답변은 제목과 관련이 없지만이 질문은 해결되었습니다. 이것은 심하게 구조화 된 질문이었고 실망 스럽지만 그대로 삭제할 수는 없습니다. 도움을 주셔서 감사하고 코드를 살펴보십시오.
Google지도를 사용하여 애플리케이션에 2 개의 일반 javascript 기능과 1 개의 jquery 기능이 있습니다. 요약하면 다음과 같습니다.
<script type="text/javascript">
window.onload = function()
{
initialize();
}
</script>
<script type="text/javascript">
var geocoder;
var markerE;
var theLocation;
var myLatlng;
var infowindow = new google.maps.InfoWindow();
var markersArray = [];
var eventMarkerArr = [];
var retrievedLatLng;
var retrievedLatLngArr = [];
var map;
$(document).ready(function(){
$('#tabs a').click(function(e){
e.preventDefault();
$(this).tab('show');
if($(this).attr("href").substring(1)=='event')
{
show('event');
hide('location');
}
else if($(this).attr("href").substring(1)=='location')
{
show('location');
hide('event');
}
});
});
function initialize() {
geocoder = new google.maps.Geocoder();
var myLatlng = new google.maps.LatLng(1.3667, 103.7500);
var myOptions = {
zoom: 13,
center: myLatlng,
mapTypeId: google.maps.MapTypeId.ROADMAP,
styles:[{
featureType: "poi.attraction",
stylers: [
{ visibility: "off" }
]},{
featureType: "poi.business",
stylers: [
{ visibility: "off" }
]
},{
featureType: "poi.government",
stylers: [
{ visibility: "off" }
]
},{
featureType: "poi.medical",
stylers: [
{ visibility: "off" }
]
},{
featureType: "poi.park",
stylers: [
{ visibility: "off" }
]
},{
featureType: "poi.place_of_worship",
stylers: [
{ visibility: "off" }
]
},{
featureType: "poi.school",
stylers: [
{ visibility: "off" }
]
},{
featureType: "poi.sports_complex",
stylers: [
{ visibility: "off" }
]
},{
}
]
};
map = new google.maps.Map(document.getElementById('map_canvas'),
myOptions);
if (postalArr) {
for (var i = 0; i < postalArr.length; i++) {
codeAddress(postalArr[i]);
}
}
else
{
document.getElementById("event_list").value = "There are no events!";
}
var locationPin = 'images/green-pin.png';
}
var address;
var eventPin = "images/blue-pin.png";
function codeAddress(postal) {
geocoder.geocode({'address': postal + ", Singapore"}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
retrievedLatLng = results[0].geometry.location;
var eventwindow = new google.maps.InfoWindow();
var markerE = new google.maps.Marker({
map: map,
position: results[0].geometry.location,
icon: eventPin,
});
markerE.mycategory = "event";
markerE.setVisible(false);
google.maps.event.addListener(markerE, 'click', function(){
eventwindow = new google.maps.InfoWindow({
content: "hello",
});
eventwindow.open(map,marker);
});
$.ajax({
type:"GET",
url: "http://maps.googleapis.com/maps/api/geocode/json?latlng="+retrievedLatLng+"&sensor=false",
dataType: "jsonp",
success: function(json){
if(json.status == 'OK')
{
alert("success");
}
}
});
eventMarkerArr.push(markerE);
retrievedLatLngArr.push("codeAddress:"+retrievedLatLng);
alert(retrievedLatLngArr[0]);
} else {
alert("Geocode was not successful for the following reason: " + status);
}
});
}
google.maps.event.addDomListener (window, 'load', initialize); 내가 latlng
을 얻을 수없는 것 때문에
나는이 일을 해요 이유입니다. 내가 처음에 한 일은 window.onload = function(){ initialize() }
으로지도를 초기화하고 .ajax 함수를 호출하는 것입니다. $(window).load(function(){...});
어느 것이 든 올바르게 얻을 수 없습니다.
혼란스러운 경우 죄송합니다. 이것이 충분하지 않은 경우 자세한 내용을 추가하겠습니다.
편집 :
results[0].geometry.location
는 6 자리 우편 번호를 지오 코딩 역에서 생산되는 위도 경도 값입니다. 전체 주소를 원하지만 6 자리 우편 번호 만 있습니다. 위도와 경도는 Google지도에 마커를 배치하는 데 사용됩니다. 그래서 전체 주소를 얻으려면 Google에서 제공하는 URL을 사용하여 json 결과를 얻으려고합니다.
더 편집 : 추가 된 코드의 전체 길이
'results'은 무엇입니까 맞다면 당신은 확인 할 수 있습니다? '$ .ajax()'호출에 성공 콜백이 없습니까? 코드를 게시 할 때 불필요한 세부 사항을 제거하는 것이 좋지만,이 경우에는 너무 많이 제거했습니다. (그리고 "jQuery 함수"는 일반적인 함수입니다.) – nnnnnn
latlng을 lat + ","+ lng로 나눌 필요가 있습니다. – Steen
예제가 꽤 완전하지 않습니다. 'someAddress' 란 무엇입니까? '결과'란 무엇입니까? 당신의 실제 문제는 무엇입니까? –