Google map api & tparkin point-in-poly - javascript

I have been working on this site for about a week now. It isnt great but then again I am not great the web design. Any tips on improvements would be greatly appreciated.
Moving on I am having a problem with point in polygon extension that tparkin wrote for the google maps api. I have read through the read me, other post and everything but I can figure out why I keep getting this error ...
a.lat is not a function
[Break On This Error] Ba(I,function(a){return!a?k:this.Z[xb]...{return new Q(this.Z.d,this.aa.d,i)};
I think it might be a problem with me using the functionality of tparkins extension incorrectly but like I said I cant figure out it.
Any help is greatly appreciated in advance.
This is the website with the script problem. Please let me know if you need any additional information.
my website.

I figured out the problem I was having. Check it out.
function codeAddress() {
var address = document.getElementById("address").value;
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
var marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location
});
var isWithinPolygon = polygon85.containsLatLng(results[0].geometry.location);
alert(isWithinPolygon);
}
else {
alert("Geocode was not successful for the following reason: " + status);
}
});
}
So the issues before was that instead of passing the coordinates results[0].geometry.location, I was passing it just location. Its a simple case of me not fully understanding what I was working with. Thank you for everyone that looked into this and sorry I wasted your time.
--Zac

Related

Google Maps Static Map using place_id as a parameter

Does anybody know how to use a place_id as a marker location on Static Maps?
In the docs https://developers.google.com/maps/documentation/maps-static/dev-guide#MarkerLocations it does not indicate whether a place_id can be used, but it seems unusual that this would be missing... Google use place_id in most of the other Maps requests.
Thank you
Currently place ID is not supported as location in Static Maps API. There is a feature request in Google issue tracker that you can see at
https://issuetracker.google.com/issues/71012469
Feel free to star this feature request to add your vote and subscribe to notifications. Hopefully Google will implement it in the future.
In the Docs I don't see a way to use the place_id parameter.
You can obtain the coordinates of a place_id and then use them in the required parameter center.
var request = {
placeId: 'ChIJOwE7_GTtwokRFq0uOwLSE9g'
};
var infowindow = new google.maps.InfoWindow();
var service = new google.maps.places.PlacesService(map);
service.getDetails(request, function(place, status) {
if (status == google.maps.places.PlacesServiceStatus.OK) {
//My URL
var gStaticMapURL = "https://maps.googleapis.com/maps/api/staticmap?center=" + place.geometry.location.lat() + "," + place.geometry.location.lng() + "&zoom=14&size=400x400&key=YOUR_API_KEY";
}
});

How to show the information for the telephone and the website and URL on google map by using InfoWindow?

Using the sample code of google map API as below, I am trying to make my google map application. But, when I search the restaurant and click the marker on the map, I can't see the information for telephone, website and can't get access to the url. What is the solution for showing the information?
Here is the sample code I referred to
https://developers.google.com/maps/documentation/javascript/examples/places-autocomplete-hotelsearch?hl=ja
Here is the code I am writing.
https://github.com/takeyan1004/javascript-application/blob/master/grf1218.html
The response of the method textSearch() hasn't the telephone, website or url of a place, you need to make other call to getDetails(place_id) to get that data.
Example:
var places = new google.maps.places.PlacesService(map);
places.getDetails({placeId: marker.placeResult.place_id},
function(place, status) {
if (status !== google.maps.places.PlacesServiceStatus.OK) {
return;
}
infoWindow.open(map, marker);
//place object has the information about phone, webste...
buildIWContent(place);
});

Delete/move Google maps marker (jquery-ui-maps)

I want to remove one marker from my Google Map, but I can't seem to get it to work. I find various answers, all telling me to use .setMap(null) on the marker, but I can't seem to get it to work.
$map_canvas = $('#map_canvas');
var youreHere_Marker;
function centerMapToAddress( address ) {
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
if( typeof youreHere_Marker!=="undefined"){
youreHere_Marker.setMap(null);
}
youreHere_Marker = $map_canvas.gmap('addMarker', {'position': results[0].geometry.location.lat()+','+results[0].geometry.location.lng(), 'bounds': true});
}
});
}
I get TypeError: youreHere_Marker.setMap is not a function. To my knowledge this means that the variable youreHere_Marker doesn't have the method .setMap(), but if I do console.log(youreHere_Marker) and inspect the object, I can see the method.
I have more markers on my map, via the MarkerClusterer. Those should remain untouched
I have the feeling I'm close, could someone point me in the right direction?
Edit: I've also tried .setPosition(), same error. I'm assuming I'm using the variable incorrect, but I don't know how to refer to it properly.
Well, i was working with google maps without jQuery, but i think (i'm not sure, but you may try) that you should get your marker with the following code:
youreHere_Marker = $map_canvas.gmap('get', 'markers')[0];
youreHere_Marker.setMap(null);
I'm really not sure that it will do what you want, but there is a possibility that this will work : )
I hope you'll solve you problems.
Thanks. : )

geocoder.geocode function does not work [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
Hi I want to geocode a location which users entered.
but it seems the geocoder.geocode function does not work
here is that part of the JavaScript
$('#inputButtonGeocode').click(function () {
var sAddress = document.getElementById('inputTextAddress').value;
geocoder.geocode({
'address': sAddress
}, function (results, status) {
if (status == google.maps.GeocoderStatus.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);
}
});
it should be a simple problem, but i cannot find the issue
he is the JSFiddle link http://jsfiddle.net/x69chen/u2gP3/7/.
Could anyone help me please, Thank you
Well there are a few things. It doesn't appear as thought your initialize function is ever being run and therefore your geocoder object is never going to be made. As well this API is not compatible with the google maps embed (iframe) API.
You can see in this example that they are creating both a geocoder and then a map using the following to create the map:
map = new google.maps.Map(document.getElementById("map-canvas"), mapOptions);
They are assigning the map to a variable called map. And then they are using that variable to pass into the creation of a marker so that that marker is placed on the right map..
var marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location
});
Also don't forget to load the actual google maps api. The jquery plugin gives you the ability to handle events in the map but it doesn't actually load the api. Here is an example of loading the API asynchronously. You can also load it like any other script, simple and easy, seen here.
You would have to refer the correct window Object. Your JavaScript is on a separate page from your iframe. You could use var theWindow = frames[number].contentWindow || frames[number].contentDocument;. Of course then you need CORS access. I would just not use an iframe. Also, I don't see your initialize() function ever being called. Is new google.maps.Map(); somewhere else? You can use the Google Maps API to load the map directly into the Element of your choice, without using an iframe. The bottom line you have to have a Map Object created with new google.maps.Map(). It will look something like:
var g = google.maps;
var map = new g.Map($('#map'), {zoom:8, center:new g.LatLng(43.472285,-80.544858)});
Of course, you can add and change attributes to the MapOpitons Object. Only after you've made a map do you have access to create a new g.Marker(). Note: I shorten google.maps to g to avoid repetitive typing.

Google Maps Geocode: unknow property premise

I'm trying to add a marker on a building/premise on google maps, to do this I'm using the Geocoding API. I tested it out by requesting an address and it worked perfectly.
var address = "...";
var geocoder = new google.maps.Geocoder();
geocoder.geocode( {'address': address }, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var location_marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location
});
}
});
According to the Geocoding API you can request a building/premise by using the premise property, but when using premise I'm getting a JavaScript error Uncaught InvalidValueError: unknown property premise.
This is how I'm requesting the premise property:
var premise = "...";
var geocoder = new google.maps.Geocoder();
geocoder.geocode( {'premise': premise }, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var location_marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location
});
}
});
I followed the answer given for this question
Not sure if anyone has had this problem before. Maybe there's another way to tackle this as well.
UPDATE
In case someone stumbles upon this question, to search businesses/places on Google Maps you can use the Places Library. This returns objects with the business's address, location, name etc.
Hopefully this helps someone :)
I there's some confusion here about what the Geocode API does. Read the API again for requests.
The required parameters are address or latlng or components, and sensor.
The optional parameters are bounds, language, region and components.
Premise is one of the properties of the returned JSON data. This means that you can't use it as a search parameter which is why the API is complaining.
The answer in that question to which you linked is wrong.
Hope this is helpful.

Categories

Resources